如何在iOS上检测UI方向是否被锁定?

9

如何检测UI方向是否被锁定?如果可以,我该如何做?

仅当UI方向未被锁定时,我想对重力传感器进行操作。


可能是重复的问题:iOS设备方向忽略方向锁定 - CRABOLO
2个回答

2
很遗憾,锁由操作系统处理,对于应用程序来说是透明的,因此无法实现。

0
为什么不尝试调用 shouldAutorotate 方法并查看返回的 BOOL 值呢?
我还没有尝试寻找 UIOrientation 锁定。但是从我的经验来看,这是我会尝试的方法。
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft])
    NSLog(@"Rotates LandscapeLeft");

if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight])
    NSLog(@"Rotates LandscapeRight");

if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait])
    NSLog(@"Rotates Portrait");

if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown])
    NSLog(@"Rotates PortraitUpsideDown");

希望这能解决你的问题。


这不起作用,因为当启用锁定时,shouldAutorotate未被调用。 - Yoko
如果锁定已启用,则它“不应该”工作。如果您想了解旋转情况,那么您应该使用UIDeviceOrientation。 - Nitin Alabur

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接