在横向模式下播放视频后状态栏下的导航栏 [英] navigation bar under status bar after video playback in landscape mode
本文介绍了在横向模式下播放视频后状态栏下的导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题:
在横向模式下播放视频后,导航栏位于状态栏下。
Navigation bar is under status bar after playing video in landscape mode.
申请:
- 仅限iOS9。
- 仅支持肖像模式。
- 视图控制器上有Web视图,Web视图将打开youtube链接
- 视图控制器嵌入在导航控制器中
- iOS9 only.
- only supports portrait mode.
- the view controller have a web view on it, web view will open a youtube link
- the view controller is embedded in a navigation controller
要重现的设置:
- 在webView中播放视频,
- 将设备置于横向模式。
- 以横向模式关闭视频播放,应用程序返回纵向模式
- 导航酒吧位置错误
- Play a video in a webView,
- Put device into landscape mode.
- Dismiss video play in landscape mode, app goes back to portrait mode
- Navigation bar is in wrong position
屏幕截图:
- 应用程序打开时
- 播放器视频并将设备放入风景
- 问题
推荐答案
Swift 3
在演示中视图控制器,覆盖 prefersStatusBarHidden
属性,仅在状态栏处于格局状态时隐藏状态栏。
In the presenting view controller, override the prefersStatusBarHidden
property to only hide the status bar if it's in landscape.
override var prefersStatusBarHidden: Bool {
return UIApplication.shared.statusBarOrientation.isLandscape
}
然后为旋转设备时添加一个观察者。
Then add an observer for when the device is rotated.
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(videoDidRotate), name: .UIDeviceOrientationDidChange, object: nil)
}
在观察者的方法中,调用 setNeedsStatusBarAppearanceUpdate
:
In the observer's method, call setNeedsStatusBarAppearanceUpdate
:
func videoDidRotate() {
self.setNeedsStatusBarAppearanceUpdate()
}
<那应该这样做。
That should do it.
这篇关于在横向模式下播放视频后状态栏下的导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文