Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

StatusBar not adhering to the app's orientation and rotating

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?

like image 713
Inertiatic Avatar asked Oct 19 '22 11:10

Inertiatic


1 Answers

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
}
like image 51
Inertiatic Avatar answered Oct 21 '22 10:10

Inertiatic