[英]Determining the Orientation of the screen rather than the orientation of the device
The [[UIDevice currentDevice] orientation]
method returns a number of orientations beyond the portrait and landscape orientation. [[UIDevice currentDevice] orientation]
方法返回纵向和横向方向以外的许多方向。 I am well aware of checking to see if the orientation returned is "valid", unfortunately if the orientation returned is NOT "valid" when my app requires a specific orientation to determine which methods to run, I have no way of knowing which method is appropriate. 我很清楚要检查返回的方向是否为“有效”,但是不幸的是,当我的应用需要特定方向来确定要运行的方法时,如果返回的方向不是“有效”,则我无法知道哪个方法是适当。
I have attempted a number of solutions to this, but for now the only thing I have been able to work out is to check to see if the orientation is LandscapeLeft
or LandscapeRight
and if it isn't I assume the screen is in portrait orientation. 我已经尝试了多种解决方案,但是到目前为止,我唯一能解决的问题就是检查方向是否为
LandscapeLeft
或LandscapeRight
,如果不是,则假定屏幕为纵向。 Unfortunately this isn't true when the device is face up and the screen is in landscape orientation. 不幸的是,当设备正面朝上且屏幕横向放置时,情况并非如此。
I attempted to use the parent view controller's orientation: 我试图使用父视图控制器的方向:
parentController.interfaceOrientation;
Unfortunately it returned UIDeviceOrientationUnknown
. 不幸的是,它返回了
UIDeviceOrientationUnknown
。 I search SO and Google for someone else who has faced this problem. 我在SO和Google中搜索遇到此问题的其他人。 It seems silly to me that Apple would have anything but
LandscapeLeft/Right
and PortraitUp/Down
for their orientations. 在我看来,Apple的方向除了
LandscapeLeft/Right
和PortraitUp/Down
,什么都不是。
What I really need is the APPS orientation not the devices, since these are sometimes at odds. 我真正需要的是APPS定位而不是设备定位,因为有时这些定位是不一致的。 Any advice?
有什么建议吗?
Have you tried using UIInterfaceOrientationPortrait
/ UIInterfaceOrientationLandscape
? 您是否尝试过使用
UIInterfaceOrientationPortrait
/ UIInterfaceOrientationLandscape
? I usually have pretty good results using these methods: 使用这些方法通常可以取得很好的效果:
if(UIInterfaceOrientationIsPortrait(viewController.interfaceOrientation)) {
//do portrait work
} else if(UIInterfaceOrientationIsLandscape(viewController.interfaceOrientation)){
//do landscape work
}
You might also try UIDeviceOrientationIsValidInterfaceOrientation . 您也可以尝试UIDeviceOrientationIsValidInterfaceOrientation 。
These will only return the app's orientation, which may not be the same as the device's orientation. 这些只会返回应用的方向,该方向可能与设备的方向不同。
If those don't work, you can also try: 如果这些方法无效,您也可以尝试:
[[UIApplication sharedApplication] statusBarOrientation]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.