Zubair
Zubair

Reputation: 945

UINavigationController's navigation bar overlaps with Status bar when user plays a video in webview

I'm using UINavigationController, works fine, problem occurs when I play a video inside a Webview & change device orientation, then navigation bar of controller overlaps with status bar, screenshot attached. I've seen these solutions ios 11 custom navbar goes under status bar , ios 11 navigation bar overlap status bar , but those solutions apply while not using navigation controller since I can't change properties of navigationController's navigation bar, any suggestions ? enter image description here

Upvotes: 1

Views: 1247

Answers (1)

Zubair
Zubair

Reputation: 945

So I was able to solve this issue, here is the solution that worked for me

open override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(updateStatusBar), name: Notification.Name.UIWindowDidBecomeKey, object: nil)

    NotificationCenter.default.addObserver(self, selector: #selector(updateStatusBar), name: Notification.Name.UIDeviceOrientationDidChange, object: nil)
}

and

@objc func updateStatusBar() {
    UIApplication.shared.isStatusBarHidden = UIApplication.shared.statusBarOrientation.isLandscape
    setNeedsStatusBarAppearanceUpdate()
}

Upvotes: 2

Related Questions