[iOS]隐藏NavigationBar但是不隐藏Navigat

2016-10-19  本文已影响0人  ioido

原文地址:http://www.jianshu.com/p/aa99f9bbfb41
http://www.cnblogs.com/superhappy/archive/2012/11/07/2759545.html
添加代理UINavigationControllerDelegate
self.navigationController.delegate = self;
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
//如果是当前控制器,则隐藏背景;如果不是当前控制器,则显示背景
if (viewController == self) {
for (UIView *view in [self.navigationController.navigationBar subviews]) {
if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {

                //最好使用隐藏,指不定什么时候你又想让他出现
                view.hidden = YES;
                
                //如果不想让它一直出现,那么可以移除
                //                [view removeFromSuperview];
            }
        }
    } else {
        for (UIView *view in [self.navigationController.navigationBar subviews]) {
            if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
                view.hidden = NO;
            }
        }
    }
}
上一篇下一篇

猜你喜欢

热点阅读