如何在 iPhone 不自动旋转的情况下检测旋转?
有人知道怎么做吗?
我认为这:
-(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 。
我的 UIViewController 位于 UINavigationController 中。
有人有主意吗?
干杯, 缺口。
Anyone know how to do this?
I thought 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 {
}
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.
My UIViewController is in a UINavigationController.
Anyone have any ideas?
Cheers,
Nick.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以注册通知
UIDeviceOrientationDidChangeNotification
(来自UIDevice.h
),然后当您关心方向变化时调用此方法:当您不再关心方向变化时,调用此方法:
在适用时会发送通知,您可以检查
[UIDevice currentDevice].orientation
以了解当前方向是什么。You can register for the notification
UIDeviceOrientationDidChangeNotification
(fromUIDevice.h
), and then when you care about orientation changes call this method:When you no longer care about orientation changes, call this method:
The notification will be sent when applicable, and you can check
[UIDevice currentDevice].orientation
to find out what the current orientation is.附带说明一下,在 2.x 中,shouldAutoRotateToInterfaceOrientation 曾经在旋转时被调用,但在 3.0 中,它的一致性要差得多。 另一篇文章中提到的通知是可靠的轮换指示的方法。
On a side note shouldAutoRotateToInterfaceOrientation used to be called on the time for rotation in 2.x, but in 3.0 it's much less consistent. The notification mentioned in the other post is the way to go for reliable indication of rotation.
您从
shouldAutorotateToInterfaceOrientation:
返回YES
,我怀疑您无意这样做。 这是防止设备旋转所需实施的唯一方法。至于获取设备的当前方向,可以使用
[[UIDevice currentDevice]orientation]
。You're returning
YES
fromshouldAutorotateToInterfaceOrientation:
, which I suspect you didn't mean to do. That's the only method you need to implement to prevent the device from rotating.As for getting the current orientation of the device, you can use
[[UIDevice currentDevice] orientation]
.