Navigation Bar Changes Height

2019-06-02 06:08发布

When I push my UIViewController to the screen from my previous controller it animates the change. But when it finishes loading it resizes my navigation bar and the jumpy transition makes it look bad. How can I fix this? All I'm doing is hiding the navigation bar in Controller A in viewWillAppear and showing it in Controller B in viewDidLoad.

enter image description here

2条回答
看我几分像从前
2楼-- · 2019-06-02 07:01

Ok solved it. In viewDidLoad of Controller B (the view controller I'm pushing) add the following:

UINavigationBar *navigationBar = self.navigationController.navigationBar;

[navigationBar setBackgroundImage:[UIImage new]
                   forBarPosition:UIBarPositionAny
                       barMetrics:UIBarMetricsDefault];

[navigationBar setShadowImage:[UIImage new]];

Then in your UIViewController's XIB make a height constraint on the navigation bar and set it to 68 (from testing the actual line seems to fall in between 68 and 69). Smooth as silk.

edit: If anyone has any better ideas please add them. I'll have to modify this solution for screen rotation so its not perfect.

查看更多
姐就是有狂的资本
3楼-- · 2019-06-02 07:14

You can do all in your controller A like this:

- (void)viewWillAppear:(BOOL)animated 
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated 
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}
查看更多
登录 后发表回答