在iPad上确定UIInterfaceOrientation [英] Determine UIInterfaceOrientation on iPad
问题描述
在这种情况下我不需要指定方向,我只需要检测它,但我遇到了麻烦。我有条件代码,只能在肖像中工作,如果设备在横向,我需要做其他事情。由于deviceOrientation不一定与interfaceOrientation相同,我无法想出一种测试纵向模式的方法。
I don't need to specify the orientation in this case, I just need to detect it, but I'm having trouble. I have conditional code that should only work in portrait, and if the device is in landscape I need to do something else. Since the deviceOrientation is not necessarily the same as the interfaceOrientation, I can't come up with a way to test for portrait mode.
我在Google上找到的大多数教程都是方法强迫风景或做某种旋转。我唯一想做的就是确定方向是什么。这是我的代码,它不起作用:
Most tutorials I find on Google are ways to force landscape or do some sort of rotation. The only thing I want to do is just determine what the orientation is. Here is my code, which is not working:
-(void)viewDidLoad {
[super viewDidLoad];
//currentOrientation is declared as UIInterfaceOrientation currentOrientation
currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSLog(@"%@",currentOrientation); // == NULL
}
我需要确定interfaceOrientation和program的值有条件的。谢谢你的帮助!
I need to determine the value of the interfaceOrientation and program conditionally. Thanks for your help!
推荐答案
你知道 interfaceOrientation
属性吗? UIViewController
类?
- (void) viewDidLoad {
[super viewDidLoad];
BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);
// now do whatever you need
}
或者你在< a href =https://developer.apple.com/documentation/uikit/uidevice/1620053-orientation?language=objc\"rel =nofollow noreferrer> [[UIDevice currentDevice] orientation]
?
这篇关于在iPad上确定UIInterfaceOrientation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!