iphone - iPad 方向未正确返回

标签 iphone ios xcode ipad

我基本上是在运行这段代码:

UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation];

if(statusBarOrientation == UIInterfaceOrientationPortrait){
     NSLog(@"orientation is portrait");
}

但是,无论模拟器或我的 iPad 中的实际方向如何,它都在打印“方向是纵向”。无论方向如何,尝试将 statusBarOrientation NSLog 为 %d 也会返回 1。

我坚持这是我的应用程序委托(delegate)、我的 View Controller 和我需要它的类,它们是同一件事。我的 info.plist/target 设置支持所有 4 种设备方向。

有没有人有确定界面方向的可靠方法,或者为什么我的不工作?谢谢

最佳答案

如果您不喜欢使用通知进行定向。然后也使用以下方法。

这是 iPad 中仅横向方向和 iPhone 中纵向的示例...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    {
        if(interfaceOrientation==UIInterfaceOrientationLandscapeLeft ||  
         interfaceOrientation==UIInterfaceOrientationLandscapeLeft)
            return YES;
        else
            return NO;
    }
    else
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }
}

关于iphone - iPad 方向未正确返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8875162/

相关文章:

javascript - 使用 React-Native 推送通知

ios - iOS 中滑动手势识别器的问题

objective-c - 设置 View Controller Storyboard ID 不起作用

ios - Xcode:仅当 PKI key 插入时,才能在钥匙串(keychain)中找到指定的项目

iphone - 在 XCode 4 中将 iPhone 应用程序转换为 iPad 应用程序

iphone - 在应用程序购买 iphone 中发送到已释放实例的消息

iphone - 单色触摸 : Enable Multisampling in OpenGL ES 2. 0

iphone - 动态设置动态生成的 UITableviews 的高度和位置?

ios - 如何在 Swift iOS 中通过 QR 扫描仪扫描时在日历中添加事件

swift - AST 反序列化问题,输入不是 PCH 文件