我有一个根视图控制器来管理其中的所有其他控制器,因此我在上述rootViewController中覆盖了shouldAutorotate和supportedInterfaceOrientations,如下所示:
public override func shouldAutorotate() -> Bool {
if let vc = view.window?.rootViewController?.presentedViewController {
if NSStringFromClass(vc.classForCoder) == "AVFullScreenViewController" {
return true
}
}
return false
}
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if let vc = view.window?.rootViewController?.presentedViewController {
if NSStringFromClass(vc.classForCoder) == "AVFullScreenViewController" {
return UIInterfaceOrientationMask.AllButUpsideDown
}
}
return UIInterfaceOrientationMask.Portrait
}
除了使用AVPlayerViewController查看全屏视频时,我的应用程序仅是纵向的。
上面的代码在整个应用程序中运行良好。我所有的控制器及其视图均保持纵向,并且当用户将视频全屏显示时,它可以毫无问题地旋转为横向。
我的问题是,纵向模式下的状态栏未粘附在方向蒙版上,而是旋转为横向,但是状态栏随后隐藏在横向中。另一个奇怪的事情是,当应用程序处于横向模式时,现在可以将控制中心和通知中心滑动为打开状态,就像应用程序处于横向模式一样。
支持的最低iOS版本是9.0。有什么建议?
我最终在根视图控制器中删除了上面的代码,并将其添加到我的应用程序委托中。状态栏现在保持不变。
func application(application: UIApplication, supportedInterfaceOrientationsForWindow window: UIWindow?) -> UIInterfaceOrientationMask {
if let vc = window?.rootViewController?.presentedViewController {
if NSStringFromClass(vc.classForCoder) == "AVFullScreenViewController" {
return UIInterfaceOrientationMask.AllButUpsideDown
}
}
return UIInterfaceOrientationMask.Portrait
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句