当前位置: 代码迷 >> 综合 >> iOS12-WKWebView-H5视频播放进入全屏状态栏丢失
  详细解决方案

iOS12-WKWebView-H5视频播放进入全屏状态栏丢失

热度:96   发布时间:2023-12-18 12:05:52.0

iOS 12 H5视频播放进入全屏的时候 返回会有一个状态栏丢失问题

//添加通知
if (@available(iOS 12.0, *)) {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeHidden:) name:UIWindowDidBecomeHiddenNotification object:nil];}
#pragma mark - notification event- (void)windowDidBecomeHidden:(NSNotification *)notification {
    //iOS 12 H5视频播放进入全屏的时候 返回会有一个状态栏丢失问题 这里监听通知解决一下UIWindow *window = (UIWindow *)notification.object;if(!window){
    return ;}UIViewController *rootVC = window.rootViewController;NSArray<__kindof UIViewController *> *vcs = rootVC.childViewControllers;if([vcs.firstObject isKindOfClass:NSClassFromString(@"AVPlayerViewController")]){
    
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
#pragma clang diagnostic pop}
}

dealloc的时候移除通知

if (@available(iOS 12.0, *)) {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIWindowDidBecomeHiddenNotification object:nil];}