0

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!

  • 1
    can you try to call it in viewDidAppear ? – Braham Youssef Dec 06 '18 at 08:34
  • 1
    Are you calling `transitionContext.completeTransition(!transitionContext.transitionWasCancelled)` even when animation is cancelled ? – CZ54 Dec 06 '18 at 08:36
  • @BrahamYoussef yes and it does not change the status bar style. – Davide Pagin Dec 06 '18 at 08:41
  • @CZ54 Yes in the completion block of the UIView.animateKeyframes – Davide Pagin Dec 06 '18 at 08:42
  • can you send me the code ? – Braham Youssef Dec 06 '18 at 08:45
  • @BrahamYoussef you can use the tab bar demo of this library [link](https://github.com/ColinEberhardt/VCTransitionsLibrary) and set the status bar style to .lightContent in one controller and to .default to another, and try to switch between these two controllers and cancel the transition (stop the gesture before the animation will complete the transition) – Davide Pagin Dec 06 '18 at 08:49
  • Can you try calling `setNeedsStatusBarAppearanceUpdate()` with a `UIView` animation method in your `viewWillAppear`? The animation might help with the race condition by introducing a delay. Just a thought. Try it if you can. – nayem Dec 06 '18 at 10:22

1 Answers1

0

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.