简体   繁体   中英

iOS 13 Status Bar Glitch

There seems to be a glitch on iOS 13 when trying to change the status bar color from one view controller to the other. The previous view controller overrides the preferred status bar style to light content. When navigating to a child view, I call the following code to set the status bar based on the interface style.

    override var preferredStatusBarStyle: UIStatusBarStyle {
        if #available(iOS 13, *) {
            if self.traitCollection.userInterfaceStyle == .dark {
                return .darkContent
            } else {
                return .lightContent
            }

        }
        return .default
    }

The status bar looks like so, where half of it is light and the time is dark (as it should be). After an arbitrary amount of time the status bar will draw properly. Ive tried calling setNeedsStatusBarDisplay(). Which does get called but does not fix the problem after a re-render. This only happens on iOS 13. Tested across multiple devices

Status bar glitch. Time is light where as battery and network icons are dark:图片

Thanks in advance!

Here is what I do to fix this issue:

@interface AHTabBarController : UITabBarController

- (UIViewController *)childViewControllerForStatusBarStyle {

    UINavigationController *navigationController = self.selectedViewController;
    navigationController.navigationBar.barStyle = UIBarStyleDefault; // status bar style

    return navigationController;
}

I got the same status bar glitch every time when I was changing UIWindow.rootViewController . It was reproducible even in empty project, created from scratch in Xcode 11 and already configured correctly by it. But on iOS 12 and below everything works fine.

I've found the solution for iOS 13 that works for me. If you update your project from Xcode 10 / iOS 12, you should add SceneDelegate to the project first (I've done it according to this manual ). Then, right after changing root view controller you should call makeKeyAndVisible :

if (@available(iOS 13, *)) {
    id<UIWindowSceneDelegate> sceneDelegate = (id<UIWindowSceneDelegate>) UIApplication.sharedApplication.connectedScenes.allObjects.firstObject.delegate;
    [sceneDelegate.window makeKeyAndVisible];
}

Sorry for Objective-C code, but Swift version is pretty similar.

this isn't a glitch this set it back to Default

override var preferredStatusBarStyle: UIStatusBarStyle {
        return self.style
    }
    var style: UIStatusBarStyle = .default

Fixed it by setting the View controller-based status bar appearance in the info.plist to NO.

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM