今天忽然发现一个问题,一个隐藏的导航栏在push到下一个页面的时候,导航栏闪了一下,着实让人难受,所以着手解决一下
一开始的写法,应该很多人都是这样写的。-(void)viewWillAppear:(BOOL)animated{ //self.navigationController.navigationBarHidden = YES; }-(void)viewWillDisappear:(BOOL)animated{ //self.navigationController.navigationBarHidden = NO;}复制代码
改完之后的写法,其实很简单,效果还是可以的-(void)viewWillAppear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:YES animated:YES]; }-(void)viewWillDisappear:(BOOL)animated{ [self.navigationController setNavigationBarHidden:NO animated:YES];}复制代码
可能运气比较好,在简书上很快就找到一个swift的解决方法。
override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true, animated: true) } override func viewWillDisappear(animated: Bool) { super.viewWillDisappear(animated) self.navigationController?.setNavigationBarHidden(false, animated: true) }复制代码