通过解决我的应用程序中的最后一个大问题,我导致了另一个可能更大的问题。我的应用程序仅支持纵向,但我希望能够以横向方式观看视频。为此,我将此方法添加到 AppDelegate:
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
guard let vc = (window?.rootViewController?.presentedViewController) else {
return .Portrait
}
if (vc.isKindOfClass(NSClassFromString("AVFullScreenViewController")!)) {
return .AllButUpsideDown
}
return .Portrait
}
工作得很好。但现在,如果我提出警报或单击某些共享按钮(打开 configureMailComposeViewController() 或 UIActivityViewController()
),我的应用程序就会崩溃。
fatal error: unexpectedly found nil while unwrapping an Optional value
2016-09-16 09:51:43.665772 App[1788:535789] fatal error: unexpectedly found nil while unwrapping an Optional value
我不明白这个问题,那个守卫不应该保护我免受这个问题的影响并返回.Portrait吗? 如果我删除该方法或只是返回 .Portrait,除了横向观看视频之外,一切都会再次正常工作。
请不要建议将我的应用程序设置为横向方向除外,并为每个 Controller 禁用它。我尝试过,但不适用于我的情况。
最佳答案
在您的AVFullScreenViewController
中,当此 View Controller 弹出或关闭时,将窗口
或状态栏
的界面方向设置为纵向。您可以在AVFullScreenViewController
的viewWillDisappear
中进行管理。
关于ios - 由于 UIInterfaceOrientationMask 在 "presentViewController"时发现 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39526627/