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

原文地址: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;
            }
        }
    }
}

你可能感兴趣的:([iOS]隐藏NavigationBar但是不隐藏NavigationItem)