Is it possible to get a "will rotate" notification on iOS, before the rotation animations are executed? Like the UIViewController method willRotateToInterfaceOrientation:duration:.

I know of UIDeviceOrientationDidChangeNotification, but that one appears to be sent after the rotation animations are executed.

I'm working in a NSObject subclass, outside of view controllers.

If there is no such notification, I was considering a hack such as adding a "fake" view to the view hierarchy (to the rootViewController's view?), and override layoutSubviews to send a custom notification. Is there a less hackish alternative?

有帮助吗?

解决方案

The UIApplicationDelegate Protocol application:willChangeStatusBarOrientation:duration:

You can use one of these two methods to see:

- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration;
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation;

Apple's UIApplicationDelegate Protocol Reference is here:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

其他提示

As far as I remember, if you check in the method that you have registered for UIDeviceOrientationDidChangeNotification, the DEVICE orientation([[UIDevice currentDevice] orientation]) is the new device orientation after rotation, but the INTERFACE orientation (self.interfaceOrientation) is still the older one. viewWillLayoutSubviews has the new interface orientation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top