StatusBar 不遵守应用程序的方向和旋转
StatusBar not adhering to the app's orientation and rotating
我有一个管理其中所有其他控制器的根视图控制器,所以我覆盖了 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
}
我有一个管理其中所有其他控制器的根视图控制器,所以我覆盖了 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
}