objective-c - 无法检测负载方向 - iPad

标签 objective-c ipad uiinterfaceorientation

我已经回答了许多不同的问题,但出于某种原因,我仍然无法让我的 iPad 检测负载方向。

似乎最好的方法是检测 statusBarOrientation:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"View Loads");

    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft
        || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"This is Landscape"); 
    } else {
        NSLog(@"This is Portrait"); 
    }
}

但它总是返回“Portrait”。我的 .plist 和 shouldAutorotateToInterfaceOrientation 设置了所有 4 个方向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
                interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
                interfaceOrientation == UIInterfaceOrientationPortrait);        
        } else {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
}

有没有人有任何其他建议?提前致谢!

最佳答案

iPad 应用程序始终以纵向模式启动,无论设备的实际方向如何(如果设备处于横向状态,它们会立即旋转为横向)。如果您稍后在程序生命周期中使用相同代码检查状态栏方向,您会看到它返回实际方向。

关于objective-c - 无法检测负载方向 - iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036748/

相关文章:

ios - 在 iOS 中使用正向地理编码获取多个地址的纬度和经度时如何添加延迟?

iphone - 如何拉伸(stretch)单元格背景图像而不像 iPhone 中的聊天气泡那样的特定部分?

ios - 状态栏是横向的,但是 [[UIApplication sharedApplication] statusBarOrientation] 返回纵向

objective-c - Obj-C 到 Swift : Block to Closure/Delegate

iphone - UIpickerView 在同一个 ScrollView 中填充多个 uitextFields

objective-c - osx - 如何实现没有可见 UI 的 OSX 服务?

iphone - CLLocationManager 在没有互联网/蜂窝连接的情况下是否可以工作?

iOS 7 iPad 方向问题,当键盘出现在 UITextField 上后 View 向上移动时

iphone - 使用 Storyboard的 Xcode 横向模式

objective-c - 复杂的多设备方向处理