Moving the navigation bar when presenting a view controller through a subclass of UIPresentationController

I am creating an iOS 8 application and using the UIPresentationController to present the view controller in my own way. (see my previous question about this here: Replicating the style of the iOS Mail App layout function ).

The problem I am facing is that when I present the controller, the navigation bar starts at a 64x maximum and then jumps / shrinks to 44 after completing the presentation. I assume that the view controller understands that it does not close the status bar, and therefore it shrinks when it comes to the final resting position. I would like the navigation bar to be 44 points higher and not jump / shorten.

The following shows what the view manager looks like at the end of a presentation. This is what I want it to look like all the time. Any thoughts on how to keep the navigation bar at 44 points all the time?

enter image description here

UPDATE (3/24/2015):

I referred to a blog post for a while to find more information on this issue. Basically, the UINavigationController draws its navigation bar with a size of 64 or 44 points, depending on whether its view coincides with the application window or not. Therefore, I need to somehow tell the navigation controller that its final resting position will not be lined up with the window and that the navigation bar should be drawn at 44 points.

http://blog.jaredsinclair.com/post/61507315630/wrestling-with-status-bars-and-navigation-bars-on

+6
source share
2 answers
Finally, I found the answer to this question. He explained this previous stack overflow message:

The navigation bar is configured after calling completeTransition: in a custom transition

Thank you for not making me use my hard money to start generosity!

+1
source

I had a problem similar to yours where the navigation bar would change after calling [transitionContext completeTransition:YES] based on the visual adjacency of the navigationBar border separating the border with the UIWindow vertex. My navigation bar was nowhere at the top, so it resized to 44 pixels instead of the usual 64px "extended-under-status-bar". To get around this, I just completed the transition before I animated my toViewController alpha and position. That is, as soon as everything was correctly positioned for the animation, I called completeTransition: to let the navigation controller adjust itself while it is invisible. So far this has not had any unforeseen side effects, and the extra alpha version, moving animation frames still continues after you completeTransition .

Here is my animateTransition: method animateTransition: in my presentation animation class, which corresponds to <UIViewControllerAnimatedTransitioning>

  UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *presentedViewController = self.presenting ? toViewController : fromViewController; UIView *containerView = [transitionContext containerView]; NSTimeInterval animationDuration = [self transitionDuration:transitionContext]; if (self.presenting) { containerView.alpha = 0.0; presentedViewController.view.alpha = 0.0; [containerView addSubview:presentedViewController.view]; [UIView animateWithDuration:animationDuration delay:0 options:kNilOptions animations:^{ containerView.alpha = 1.0; } completion:^(BOOL finished) { presentedViewController.view.frameTop += 20; //I complete the transition here, while my controller view is still invisible, // but everything is in its proper place. This effectively positions everything // for animation, while also letting the navigation bar resize itself without jarring visuals. [transitionContext completeTransition:YES]; //But we're not done quite yet... [UIView animateWithDuration:animationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ presentedViewController.view.frameTop -= 20; presentedViewController.view.alpha = 1.0; } completion:nil]; }]; } if (!self.presenting) { [UIView animateWithDuration:animationDuration delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ presentedViewController.view.alpha = 0.0; presentedViewController.view.frameTop += 20; } completion:^(BOOL finished) { [UIView animateWithDuration:animationDuration delay:0 options:kNilOptions animations:^{ containerView.alpha = 0.0; } completion:^(BOOL done) { [transitionContext completeTransition:YES]; }]; }]; } 

I hope this helps anyone who is in my position!

+1
source

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


All Articles