NavigationBar 隐藏,显示控制(完美解决)


场景: 在某种情况下,一级页面隐藏Navigationbar, 而二级页面就得打开navigationbar, 这种情况,如果采取默认的Viewwillappear中处理,则会出现大片空白,那怎么解决呢? 这个问题在新融源遇到过一次,这次完美解决了


解决如下:

1、一级页面直接隐藏带哦Navigationbar, 废话

2、在一级页面写上下面这句

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


3、在二级页面展示Navigationbar,然后写上:

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

到此:完美解决了展示的问题



更好的解决方案:


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

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    if ( self.navigationController.childViewControllers.count > 1 ) {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
}

你可能感兴趣的:(iOS)