UIViewControllerAnimatedTransitioning with UIStatusBarAnimation

i implemented the method in ViewController A

- (BOOL)prefersStatusBarHidden { return NO; } 

i implemented the method in ViewController B

 - (BOOL)prefersStatusBarHidden { return YES; } - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { return UIStatusBarAnimationSlide; // when doing hiding animation i want it to slide up } 

i implemented a class T that corresponds to the viewController say AtoBTransition , I used this ViewControllerTransition to switch from vc (viewcontroller) A to vc B. when transitioning to vc B i want the status bar to slide up (hide with sliding animation) , but in In this case, it seems that he don’t make this moving animation.

Questions: Just suppose I did not make UIStatusBar related code in class T and did not add the View controller-based status bar appearance value to the info plist. And the T transition works fine as needed.

  • I'm sure the code reads at -preferredStatusBarUpdateAnimation , doing a breakpoint or logging, but why didn't it hide the status bar animation when shifting? when I switch to slowdown in the simulator. It seems that he is not doing the animation.

  • My theory is that it conflicts with the context of the transition animation, so that you can make the UIStatusBar hide animation as part of the T implementation as part of the transition scheme?

  • Can I make a UIStatusBar animation with ViewControllerAnimationTransition?

Feel free to clean some things. thanks in advance. :)

+6
source share
1 answer

I do not think you can do this directly with the API transition to the iOS 7 controller.

Now I assume that based on the hooks for this API and the status bar API, that the status bar is animal for itself and is not available for animation with a custom transition. I think this is because, when the UIViewControllerContextTransitioning transitionContext is created for you, controller A is already added to it by containerView and because you are responsible for adding the view controller B to containerView (because you need to go to it) all the manipulation methods with a type B controller start when you do this.

However, you can animate the UIApplication keyWindow frame during the transition to the animation. So, in the -animateTransition: method of your class that implements UIViewControllerAnimatedTransitioning .

 [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ [UIApplication sharedApplication].keyWindow.frame = CGRectMake(0, 0, 320, 568); // move frame up } completion:^(BOOL finished) { // assuming [UIApplication sharedApplication].keyWindow.frame = CGRectMake(0, 20, 320, 568); //move frame down }]; 

If you move on to this approach, you may have to adjust the key box frame in controller A to lower it below the status bar and apply light / dark if necessary. Then do the opposite to get the effect that you want to see in controller B. Its nasty, but it can work.

+1
source

Source: https://habr.com/ru/post/971875/


All Articles