=@{NSForegroundColorAttributeName: self.notLucencyTitleColor,NSFontAttributeName:[UIFont systemFontOfSize:18]};
[self setNavigationLeftItemWithImageName:@"more_dark"];
[self.rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.lightStatusBar = NO;
}
//透明导航栏
-(void)setBackNavDiaphanous
{
self.navigationController.navigationBar.titleTextAttributes= @{NSForegroundColorAttributeName: self.lucencyTitleColor,NSFontAttributeName:[UIFont systemFontOfSize:18]};
[self setNavigationLeftItemWithImageName:@"navigationBack"];
[self.rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
self.lightStatusBar = YES;
}
3.当tableview有组头并且组头要悬浮在导航栏下面,需要做的处理。
self.contentHeight为tableview的占屏大小,如果contentSize不用滑动就能显示完整,contentInset就不要修改,不然向上滑会有点bug。
self.offsetChange参数:没组头一般默认64就行,有组头则为组头到顶部的距离
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (self.tableView.contentSize.height >= self.contentHeight) {
//导航栏渐变处理
if (offset >= self.offsetChange) {
self.tableView.contentInset = UIEdgeInsetsMake(KStatusBarAndNavigationBarHeight, 0, 0, 0);
}else{
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
}
}
}
整体-(void)scrollViewDidScroll:(UIScrollView *)scrollView 方法里面就是做上面三件事啦
做完这些就可以实现渐变了,项目中用的比较多的话直接继承设置一下参数就可以了。
demon地址:https://github.com/yizhixiafancai/ShadeViewController