archanger archanger - 1 month ago 10
iOS Question

UINavigationBar height when changing UINavigationController

Need help.

I have some kind of custom view controller with menu like in Facebook app.
Of course, this controller manipulate with child controllers, that provide views for adding them to "root view of controller with menu".

For some design reason, when menu slide, central view have scaling.
So, the problem is: when central view from navigationController it initialized Ok.
when I change controller to another navigation controller or to the same, navigation bar has heigh changing. See snaps.

How could I prevent this behavior? any ideas?

Thanks.
P.S.: sorry for my English.

Initial view:

enter image description here

Then some sort of menu slide:

enter image description here

Then I change navigation controller ([storyboard instantiateViewControllerWithIdentifier:@"identifier"]);

enter image description here

and slide back, but navigation bar have size without consider status bar...

enter image description here

This method responsible for changing center view controller:

- (void)setCenterViewController:(UIViewController *)centerViewController{
if([centerViewController isEqual:self.centerViewController])
return;

CGRect previousFrame = CGRectZero;
CGFloat previousScale = 0.f;
if(_centerViewController)
{
[_centerViewController removeFromParentViewController];
_centerViewController.trippleController = nil;
[_centerViewContainer removeFromSuperview];
previousFrame = _centerViewController.view.frame;
previousScale = _centerViewController.view.transform.a;
}

[centerViewController removeFromParentViewController];
_centerViewController = centerViewController;
[self addChildViewController:_centerViewController];
_centerViewController.trippleController = self;

self.centerViewContainer = _centerViewController.view;
self.centerViewContainer.clipsToBounds = YES;

if(!CGRectEqualToRect(previousFrame, CGRectZero))
{
self.centerViewContainer.transform = GAffineTransformMakeScale(previousScale, previousScale);
self.centerViewContainer.frame = previousFrame;
}

[self.view insertSubview:self.centerViewContainer atIndex:0];}

Answer

So, if someone interesting, after some time experimenting, I just wrap in.

dispatch_async(dispatch_get_main_queue(), ^{
    self.centerViewContainer.transform = GAffineTransformMakeScale(previousScale, previousScale);
    self.centerViewContainer.frame = previousFrame;
})` 

and nav bar stop changing his height.

Comments