当用户在webview中播放视频时,UINavigationController的导航栏与状态栏重叠

时间:2018-04-26 07:52:27

标签: swift uinavigationcontroller ios11 statusbar xcode9.2

我正在使用UINavigationController,工作正常,当我在Webview中播放视频时会出现问题。更改设备方向,然后控制器的导航栏与状态栏重叠,附加屏幕截图。我已经看到了这些解决方案ios 11 custom navbar goes under status bar ios 11 navigation bar overlap status bar ,但这些解决方案适用于不使用导航控制器,因为我无法更改navigationController的导航栏的属性,任何建议? enter image description here

1 个答案:

答案 0 :(得分:2)

所以我能够解决这个问题,这是适用于我的解决方案

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)
}

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