【iOS】iOS navigationBar在个别界面中透明处理

导航条在个别界面中透明处理

我们平时在写界面的时候,会遇到,要把某个界面的导航条给隐藏起来 而其他界面中,而在隐藏的时候又会有条黑线出现,加个动画来处理就行了,又要有导航条,那么我们就可以在控制器的viewWillAppear、viewWillDisappear来做处理:

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [UIView animateWithDuration:1 animations:^{
        [[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:0];
        
        //设置导航栏透明
        UINavigationBar *navBar = [UINavigationBar appearance];
        navBar.shadowImage = [UIImage new];
        self.edgesForExtendedLayout=UIRectEdgeTop;
        navBar.translucent = YES;
        self.automaticallyAdjustsScrollViewInsets=NO;
        self.extendedLayoutIncludesOpaqueBars = YES;
        
    }];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:1];
    //    return;
    
    UINavigationBar *navBar = [UINavigationBar appearance];
    navBar.shadowImage = [UIImage new];
    
    [navBar setBackgroundImage:[UIImage imageWithColor:UIColorFromRGB(0x1f9bfd)] forBarMetrics:UIBarMetricsDefault];
    self.edgesForExtendedLayout=UIRectEdgeNone;
    navBar.translucent = NO;
    self.automaticallyAdjustsScrollViewInsets=YES;
    self.extendedLayoutIncludesOpaqueBars = NO;
    
}


你可能感兴趣的:(【iOS】iOS navigationBar在个别界面中透明处理)