上一篇说到自定义导航栏,若自定义的导航栏中设置了属性translucent = NO(作用是去掉颜色渲染,若为YES,与你想要的颜色存在一点的色差),导航栏的透明度会遇到问题。
若我们需要设置导航栏透明:正常的情况下,我们只需要这么做:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//自定义导航栏并在其中设置了UINavigationbar的translucent属性为NO时 打开下面一行
//self.navigationController.navigationBar.translucent = YES;
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:0];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
//自定义导航栏并在其中设置了UINavigationbar的translucent属性为NO时 打开下面一行
//self.navigationController.navigationBar.translucent = NO;
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:1];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y;
[[[self.navigationController.navigationBar subviews] objectAtIndex:0] setAlpha:offsetY/(self.headerViewHeightConst.constant - 65)];
}