NSException: "Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation'



这是一个用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

我正在开发一款应用程序,它要求拿起手机时要"上下颠倒",这样后置摄像头就一直在底部。为了反映这一点,我的信息。plist包括:

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

这个应用程序很小,只有一个视图控制器,其中包括

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

应用程序会自动终止。我能够在不同的时间内构建和使用应用程序,也就是说,我不能"导致"错误发生。

方向由三个文件决定:

  1. Info.plist

  2. 视图控制器(s)

  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
}

相关内容

最新更新