问题是:
在横向模式下播放视频后,导航栏位于状态栏下。
应用程序:
仅限
要复制的设置:
截图:
当应用程序打开
中
发布于 2016-11-04 05:48:25
Swift 3
在呈现视图控制器中,覆盖prefersStatusBarHidden
属性,以便仅在状态栏处于横向时才隐藏它。
override var prefersStatusBarHidden: Bool {
return UIApplication.shared.statusBarOrientation.isLandscape
}
然后添加设备何时旋转的观察者。
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(videoDidRotate), name: .UIDeviceOrientationDidChange, object: nil)
}
在观察者的方法中,调用setNeedsStatusBarAppearanceUpdate
func videoDidRotate() {
self.setNeedsStatusBarAppearanceUpdate()
}
这应该就行了。
发布于 2017-11-30 19:54:36
这很简单,
swift 3
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews();
UIApplication.shared.isStatusBarHidden = false
}
发布于 2017-08-04 20:14:30
@Aaron answer几乎可以工作,只有一个问题:当你在视频中点击“完成”,同时仍然将设备放在横向,它不会显示状态栏,直到你将你的设备旋转回肖像。
在这种情况下,我添加了通知观察者,当点击“完成”按钮,然后我切换到肖像编程。
我的代码在Objective C中:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoDidRotate) name:UIDeviceOrientationDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closedFullScreen:) name:UIWindowDidBecomeHiddenNotification object:nil];
}
-(void)closedFullScreen:(NSNotification *)myNotification{
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
}
- (BOOL)prefersStatusBarHidden {
return UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
}
- (void)videoDidRotate {
[self setNeedsStatusBarAppearanceUpdate];
}
编辑:
必须将.plist文件中基于控制器的查看状态栏外观设置为YES。
https://stackoverflow.com/questions/35804693
复制相似问题