这是来自一个用 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
}
应用程序会自发终止。我能够构建和使用该应用程序不同的时间,即我无法“导致”错误发生。
最佳答案
方向由三个文件确定:
Info.plist
View Controller
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/