如何在没有设备自动旋转的情况下检测iPhone上的旋转? [英] How do I detect a rotation on the iPhone without the device autorotating?
问题描述
任何人都知道如何做到这一点?
Anyone know how to do this?
我认为这样:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
}
- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
}
- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
}
- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration {
}
可以防止设备旋转(覆盖我的UIViewController的所有旋转方法,而不是调用超类),但我担心它不是实际执行旋转的UIViewController。
may prevent the device from rotation (overriding all rotate methods of my UIViewController and not calling the superclass) but I fear it's not the UIViewController that actually performs the rotation.
我的UIViewController在一个UINavigationController中。
My UIViewController is in a UINavigationController.
任何人都有什么想法?
推荐答案
您可以注册通知 UIDeviceOrientationDidChangeNotification
$ c> UIDevice.h ),然后当你关心方向变化时调用这个方法:
You can register for the notification UIDeviceOrientationDidChangeNotification
(from UIDevice.h
), and then when you care about orientation changes call this method:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
当您不再关心方向更改时,请调用此方法:
When you no longer care about orientation changes, call this method:
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
通知将在适当时发送,您可以检查 [UIDevice currentDevice ] .orientation
,找出当前的方向。
The notification will be sent when applicable, and you can check [UIDevice currentDevice].orientation
to find out what the current orientation is.
这篇关于如何在没有设备自动旋转的情况下检测iPhone上的旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!