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

6

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.

Dishpan answered 2/9, 2018 at 11:20 Comment(5)
This happens with the video player as well when returning from full-screen. Also started in iOS 12.Lateral
Same issue for me after coming from fullscreen. Any fixes?Farrish
Did you get any solution on it?Oneness
I'd also be interested in the solution.Dulcimer
I get the error on iOS 12, but not on iOS 13. Did not have any entries in info.plist regarding StatusbarTobolsk
E
10

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.

Eared answered 23/10, 2018 at 8:28 Comment(0)
B
5

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

Billiards answered 8/4, 2019 at 4:3 Comment(1)
setStatusBarHidden: animated: is deprecated one. You should use Use -[UIViewController prefersStatusBarHidden]Barraza
D
1

Create one extension of AVPlayerViewController like below this slo

extension AVPlayerViewController {
    open override var prefersStatusBarHidden: Bool {
        return false
    }
}
Discordant answered 6/5, 2020 at 5:53 Comment(0)
D
0

In the end I used category in objective-c to deal with this problem. I set View controller-based status bar appearance to YES and add code below

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden
{
    return NO;
} 

As for my experience, you have to also implement code above in UINavigationViewController. It seems that it has its own implementation for that. And also every window to see if there is a rootViewController exist, if there isn't, then add one for it.

Although this solution is a bit Cumbersome, but that is the one I solved my issue perfectly so far.

Dishpan answered 11/12, 2018 at 10:11 Comment(0)
B
0

If you want the status bar to be white, technically to be .lightContent, follow the steps below:

  1. In Info.plist, set View controller-based status bar appearance = YES
  2. Create an extenstion to either UIViewController or UINavigationController, and write the following codes:
    open override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
    }
    
    open override var prefersStatusBarHidden: Bool {
        return false
    }

Note: In case the status bar turns back to dark, you may need to trigger a call of self.setNeedsStatusBarAppearanceUpdate() inside viewWillAppear() to inform the status bar to refresh itself.

Hope that helps !!! Have a nice one!

Behnken answered 28/9, 2020 at 6:37 Comment(0)
W
-1

Subscribe for

UIWindowDidBecomeHiddenNotification

event

NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIWindowDidBecomeHiddenNotification"), HandleAction);

and set the status bar state in handler:

void HandleAction(NSNotification obj)
{
    UIApplication.SharedApplication.StatusBarHidden = false;
}
Winola answered 28/2, 2019 at 14:9 Comment(1)
Hello and welcome to stackoverflow, remember to consider pointing the user to the documentation and reasoning about your answer before copy pasting code. Thank you for your contribution.Supposed

© 2022 - 2024 — McMap. All rights reserved.