iOS|iOS navigationbar 隐藏时黑边问题

今天在做项目时,出现了navigationbar 隐藏/显示 出现黑边问题,搞了好久,终于找到解决办法。。。 1.在网上找了好久,基本上都是以下的方法,如下: 1.1 在页面即将出现时隐藏navgaionbar

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

1.2 在页面即将消失时显示navgaionbar
- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.navigationController setNavigationBarHidden:NO animated:animated]; }

结果悲剧的发现黑边情况还是会出现,因为上述方法是针对页面间push时有作用,但是项目中我的页面是present一个登录页,坑啊,还好找到了如下方法,使用navigationController的代理方法: 2.1 页面即将出现时设置代理
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.delegate = self; }

2.2 页面消失时取消代理
- (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; if (self.navigationController.delegate == self) { self.navigationController.delegate = nil; } }

代理方法
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated { if (viewController == self) { [self.navigationController setNavigationBarHidden:YES animated:YES]; }else{ [self.navigationController setNavigationBarHidden:NO animated:YES]; } }

    推荐阅读