Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

status bar disappeared after full screen video in WKWebView only in iOS 12

As you can see this only happened in iOS 12.

iOS 12              iOS 11

enter image description hereenter image description here

here is my code:

import UIKit
import WebKit

class ViewController: UIViewController {

    override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }

    override var prefersStatusBarHidden: Bool {
        return false
    }

    var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        webView = WKWebView(frame: UIScreen.main.bounds)
        view.addSubview(webView)
        webView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
        webView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        webView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
        webView.loadHTMLString("<p><iframe src=\"https://www.youtube.com/embed/HCjNJDNzw8Y\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"\"></iframe></p>", baseURL: URL(string: "https://www.youtube.com/"))
        setNeedsStatusBarAppearanceUpdate()
    }
}

my info.plist is right below: enter image description here

Does anyone know how to solve it?

I know that if I set the key View controller-based status bar appearance to YES will help, but In that case it will look like this:

enter image description here

There are unknown reason for changing status bar from white and black, and as for my real project is in a large scale, so it will be nice to solve in the original setting, rather than make every ViewController inherit from one class which is subclass from UIViewController or add dynamic for overriding prefersStatusBarHidden and preferredStatusBarStyle in extension (here just try to force it show update status bar when View controller-based status bar appearance set to YES)

Hope there is a solution for View controller-based status bar appearance set to NO, that will be very helpful thx.

here is the demo project, it was created by Xcode9.4, feel free to try it with.

like image 636
andrew54068 Avatar asked Sep 02 '18 11:09

andrew54068


3 Answers

Remove Following property from info.plist file. and Give it programmatically only.

Status bar is initially hidden : NO

View controller-based status bar appearance : NO

Status bar style : UIStatusBarStyleLightContent

It may be work for you.

like image 110
Ladumor Dineshkumar Avatar answered Nov 19 '22 12:11

Ladumor Dineshkumar


Use this solution:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  ...
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoExitFullScreen:) name:@"UIWindowDidBecomeHiddenNotification" object:nil];
...
}

- (void)videoExitFullScreen:(id)sender
{
  [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
}

Reference more here:

https://github.com/react-native-community/react-native-webview/issues/62

like image 28
Nguyen Thuong Thong Avatar answered Nov 19 '22 12:11

Nguyen Thuong Thong


Create one extension of AVPlayerViewController like below this slo

extension AVPlayerViewController {
    open override var prefersStatusBarHidden: Bool {
        return false
    }
}
like image 1
Rahul Chaturvedi Avatar answered Nov 19 '22 12:11

Rahul Chaturvedi