ios - NSException : "Terminating app due to uncaught exception ' UIApplicationInvalidInterfaceOrientation', 原因 :. ..”

标签 ios swift uiinterfaceorientation autorotate

这是来自一个用 swift 编写的 iPhone 应用程序:

*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', 
reason: 'Supported orientations has no common orientation with the application, 
and [UICompatibilityInputViewController shouldAutorotate] is returning YES
*** First throw call stack:
(0x1836984d0 0x198107f9c 0x183698418 0x188d7a1d0 0x188d833dc 0x188d83354     
0x188d81e3c 0x188cfe8fc 0x188cfdc0c 0x184581220 0x188cfda90 0x188d0ad08 
0x1895558e4 0x189556944 0x188d11af8 0x189556740 0x1895505d4 0x188dccd90 
0x18939b3dc 0x18939b5ec 0x18d43bb20 0x18d43bea0 0x18364fd6c 0x18364f800 
0x18364d500 0x18357d280 0x18e6f40cc 0x188d6adf8 0x100120d94 0x19894a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

我正在构建一个该应用程序,要求将手机保持“PortraitUpsideDown”,以便后置摄像头始终位于底部。为了反射(reflect)这一点,我的 Info.plist 包括:

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>

该应用程序很小,并且只有一个 View Controller ,其中包括

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return UIInterfaceOrientationMask.PortraitUpsideDown
}

override func shouldAutorotate() -> Bool {
   return false
}

应用程序会自发终止。我能够构建和使用该应用程序不同的时间,即我无法“导致”错误发生。

最佳答案

方向由三个文件确定:

  1. Info.plist

  2. View Controller

  3. AppDelegate

Info.plist 必须包含

<key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>

ViewController.swift 必须包含

override func shouldAutorotate() -> Bool {
        return false
    }
override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
        return UIInterfaceOrientation.PortraitUpsideDown
    }

AppDelegate.swift 必须包含

func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.PortraitUpsideDown
}

关于ios - NSException : "Terminating app due to uncaught exception ' UIApplicationInvalidInterfaceOrientation', 原因 :. ..”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31866398/

相关文章:

iphone - 当方向改变时如何管理应用程序?

快速过滤功能

ios - 如何更改某些功能以与 iOS 10 或更低版本兼容,以便我的 snapchat 中的某些功能(如相机 View Controller )

ios - 加载 UICollectionViewCell Swift 4 时单元格闪烁问题

iphone - 当设备方向改变时图像动画自动停止

ios - 更改 MBProgressHUD Loader 的位置

objective-c - UIDocumentInteractionController 将无法在 Ibook 中打开文档

javascript - iOS 混合应用程序 - Google map API 错误 : RefererNotAllowedMapError

ios - 在 Amazon Web Service SS3 存储桶中为 iOS 应用程序 Adhoc 配置 HTTPS 访问

ios10 - iOS : status bar and keyboard rotates after app in background