문제

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