在这种情况下,我不需要指定方向,我只需要检测它,但我遇到了麻烦。我有条件代码只能在纵向工作,如果设备处于横向,我需要做其他事情。由于 deviceOrientation 不一定与 interfaceOrientation 相同,因此我无法想出测试纵向模式的方法。
我在 Google 上找到的大多数教程都是强制横向或进行某种旋转的方法。我唯一想做的就是确定方向是什么。这是我的代码,它不起作用:
-(void)viewDidLoad {
[super viewDidLoad];
//currentOrientation is declared as UIInterfaceOrientation currentOrientation
currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSLog(@"%@",currentOrientation); // == NULL
}
我需要确定 interfaceOrientation 的值并有条件地进行编程。感谢您的帮助!
最佳答案
您知道 UIViewController
类的 interfaceOrientation
属性吗?
- (void) viewDidLoad {
[super viewDidLoad];
BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);
// now do whatever you need
}
关于iphone - 确定 iPad 上的 UIInterfaceOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2614274/