1

I'm presenting a view controller using the transitioning delegate modally from my root view controller.

UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
UIViewController *rootVC = [window rootViewController];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:authVC];
navController.modalPresentationStyle = UIModalPresentationCustom;
navController.navigationBar.translucent = NO;
navController.transitioningDelegate = self;
[rootVC presentViewController:navController animated:YES completion:nil];

My transitioning delegate adds the view as follows, where authorizationVC is the login view pictured in the screenshots.

UIView *containerView = [transitionContext containerView];
[containerView addSubview:blurredView];
[containerView insertSubview:_authorizationVC.view aboveSubview:blurredView];

_authorizationVC.view.frame = CGRectMake(10, 30, 300, 450);

At first, the view animates in, and the navigation bar is full height, what I believe to be 64 pixels (44 for the nav bar and 20 for the status bar).

Full height nav bar

As soon as my animation completes, the nav bar shrinks to 44 pixels. The transition is jarring. The content inside my view controller is unaffected.

Nav bar with correct height (44 pixels)

How do I avoid this jittering navigation bar? The second image is what I'd like to achieve.

2 Answers 2

2

Set all the properties of the view before adding it to its superview.

UIView *containerView = [transitionContext containerView];
_authorizationVC.view.frame = CGRectMake(10, 30, 300, 450); /// Change the frame FIRST!

[containerView addSubview:blurredView];
[containerView insertSubview:_authorizationVC.view aboveSubview:blurredView];

Voila! The nav bar acts as expected.

1

I would avoid using a UINavigationController if you don't really need it.

The UINavigationController takes into account the topLayoutGuide in the way it sizes the navigation bar. If you just want the coloured bar and close button, I'd simplify it and use your own views for that.

If you must use a UINavigationController you could try playing with the status bar's appearance and see how it affects the navigation controller's presentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.