I have a root view controller that manages all other controllers inside it of, so I overrode shouldAutorotate and supportedInterfaceOrientations in said rootViewController like this:
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
}
My app is portrait only except for when viewing fullscreen video using AVPlayerViewController.
The code above is working great across the entire app. All of my controllers and their views stay in portrait and when a user takes a video full screen, it rotates to landscape without issues.
My issue is that the status bar in portrait mode is not adhering to the orientation mask and rotates to landscape, but the status bar is then hidden in landscape. The other strange thing is that when the app is in landscape, control center and notification center can now be swiped open as if the app is in landscape.
Min supported iOS is 9.0. Any suggestions?
I ended up removing the above code in my root view controller and adding this into my app delegate. Status bar now stays put.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With