[英]Determining the Orientation of the screen rather than the orientation of the device
[[UIDevice currentDevice] orientation]
方法返回纵向和横向方向以外的许多方向。 我很清楚要检查返回的方向是否为“有效”,但是不幸的是,当我的应用需要特定方向来确定要运行的方法时,如果返回的方向不是“有效”,则我无法知道哪个方法是适当。
我已经尝试了多种解决方案,但是到目前为止,我唯一能解决的问题就是检查方向是否为LandscapeLeft
或LandscapeRight
,如果不是,则假定屏幕为纵向。 不幸的是,当设备正面朝上且屏幕横向放置时,情况并非如此。
我试图使用父视图控制器的方向:
parentController.interfaceOrientation;
不幸的是,它返回了UIDeviceOrientationUnknown
。 我在SO和Google中搜索遇到此问题的其他人。 在我看来,Apple的方向除了LandscapeLeft/Right
和PortraitUp/Down
,什么都不是。
我真正需要的是APPS定位而不是设备定位,因为有时这些定位是不一致的。 有什么建议吗?
您是否尝试过使用UIInterfaceOrientationPortrait
/ UIInterfaceOrientationLandscape
? 使用这些方法通常可以取得很好的效果:
if(UIInterfaceOrientationIsPortrait(viewController.interfaceOrientation)) {
//do portrait work
} else if(UIInterfaceOrientationIsLandscape(viewController.interfaceOrientation)){
//do landscape work
}
您也可以尝试UIDeviceOrientationIsValidInterfaceOrientation 。
这些只会返回应用的方向,该方向可能与设备的方向不同。
如果这些方法无效,您也可以尝试:
[[UIApplication sharedApplication] statusBarOrientation]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.