導(dǎo)航條在個(gè)別界面中透明處理
我們平時(shí)在寫界面的時(shí)候,會(huì)遇到,要把某個(gè)界面的導(dǎo)航條給隱藏起來(lái) 而其他界面中,而在隱藏的時(shí)候又會(huì)有條黑線出現(xiàn),加個(gè)動(dòng)畫來(lái)處理就行了,又要有導(dǎo)航條,那么我們就可以在控制器的viewWillAppear、viewWillDisappear來(lái)做處理:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[UIView animateWithDuration:1 animations:^{
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:0];
//設(shè)置導(dǎo)航欄透明
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;
}