Davide Pagin
Davide Pagin

Reputation: 21

Incorrect preferredStatusBarStyle when controller animated transitioning is canceled

I have a UITabViewController which embeds some UIViewControllers. These controllers could have a different preferredStatusBarStyle.

I use a UIViewControllerAnimatedTransitioning+UIPercentDrivenInteractiveTransition to switch between controllers using a UIScreenEdgePanGestureRecognizer.

I noticed that if i start a transitioning between two controllers with different preferredStatusBarStyle and i cancel the transitioning, the status bar style does not return to the first controller preference but it remains to the second one. Obviously if i complete the transitioning, or switch between controllers using the tab bar items, the status bar style changes correctly.

I tried to call setNeedsStatusBarAppearanceUpdate() in every viewWillAppear, but the status bar does not change.

I know i can change the status bar style with UIApplication.shared.statusBarStyle setter, but this method is now deprecated.

I also tried to change the animation for the transitions, but the problem does not disappear.

The strange thing is that the preferredStatusBarStyle of the "from" view controller, when the transition is canceled, is set to the correct value, but it is displayed as the opposite!

Upvotes: 0

Views: 160

Answers (1)

Davide Pagin
Davide Pagin

Reputation: 21

I found a workaround for this problem (it's not perfect but it works out)

In the viewWillAppear of the first controller (the "from" one), call this animation.

DispatchQueue.main.async {
    UIView.animate(withDuration: duration, delay: delay, options: options, animations: {

        self.setNeedsStatusBarAppearanceUpdate()

    }, completion: nil)
}

In this way, when you cancel the transition, for a moment you'll see the status bar of the second view controller and then the status bar will return to the first controller one.

Upvotes: 0

Related Questions