Hon*_*ang 25 iphone objective-c ios swift
问题:
在横向模式下播放视频后,导航栏处于状态栏下方.
应用程序:
设置重现:
截图:
Aar*_*ron 22
斯威夫特3
在呈现视图控制器中,覆盖该prefersStatusBarHidden属性以仅隐藏状态栏(如果它在横向中).
override var prefersStatusBarHidden: Bool {
return UIApplication.shared.statusBarOrientation.isLandscape
}
Run Code Online (Sandbox Code Playgroud)
然后添加一个观察器,以便旋转设备.
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(videoDidRotate), name: .UIDeviceOrientationDidChange, object: nil)
}
Run Code Online (Sandbox Code Playgroud)
在观察者的方法中,调用setNeedsStatusBarAppearanceUpdate:
func videoDidRotate() {
self.setNeedsStatusBarAppearanceUpdate()
}
Run Code Online (Sandbox Code Playgroud)
应该这样做.
Dan*_*per 11
这很简单,
迅捷3
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews();
UIApplication.shared.isStatusBarHidden = false
}
Run Code Online (Sandbox Code Playgroud)
@Aaron的回答几乎可以解决,只有一个问题:当你点击视频中的"完成",同时仍然以横向方向握住设备时,它将不显示状态栏,直到你将设备旋转回肖像.
在那种情况下,我在点击"完成"按钮时添加了通知观察者,然后我以编程方式切换到肖像.
我的代码在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];
}
Run Code Online (Sandbox Code Playgroud)
编辑:
在.plist文件中查看基于控制器的状态栏外观必须设置为YES.
| 归档时间: |
|
| 查看次数: |
4964 次 |
| 最近记录: |