iphone - 确定 iPad 上的 UIInterfaceOrientation

标签 iphone ipad orientation

在这种情况下,我不需要指定方向,我只需要检测它,但我遇到了麻烦。我有条件代码只能在纵向工作,如果设备处于横向,我需要做其他事情。由于 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
}

或者你在寻找[[UIDevice currentDevice] orientation]

关于iphone - 确定 iPad 上的 UIInterfaceOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2614274/

相关文章:

iphone - 如何以编程方式在 iOS 应用程序中显示目标的版本/内部版本号?

iphone - 生成预览后 ARC 转换错误

android - 解锁设备时 onConfigurationChanged 不是第一次调用

iPhone SQLite 选择查询不起作用

ios - Weirdcore 数据 react - 未检测 NSManagedObject 子类

ios - 如何在 iOS 应用程序中评论 instagram 提要

Android VideoView横向方向问题

应用委托(delegate)中出现平面问题时的 iPad 启动方向

iphone - 在 xcode 中通过 gdb 检查属性值

iPhone - 带有标签栏 Controller 的应用程序 - 在顶部显示间隙