Navigation Bar Changes Height

安稳与你 提交于 2020-01-14 03:23:38

问题


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.


回答1:


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.




回答2:


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];
}


来源:https://stackoverflow.com/questions/32414679/navigation-bar-changes-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!