#define oriOfftY -244
#define oriHeight 200
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstr;
self.tableView.contentInset = UIEdgeInsetsMake(244, 0, 0, 0);
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//求偏移量
//当前点 - 最原始的点
NSLog(@"最原始的点.y%f",scrollView.contentOffset.y);
CGFloat offset = scrollView.contentOffset.y - oriOfftY;
NSLog(@"offset======%f",offset);
CGFloat h = oriHeight - offset;
if (h < 64) {
h = 64;
}
self.heightConstr.constant = h;
//根据透明度来生成图片
//找最大值/这里最大值是1
CGFloat alpha = offset * 1 / 136.0;
if (alpha >= 1) {
alpha = 0.99;
}
//拿到标题
UILabel *titleL = (UILabel *)self.navigationItem.titleView;
titleL.textColor = [UIColor colorWithWhite:0 alpha:alpha];
//把颜色生成图片
UIColor *alphaColor = [UIColor colorWithWhite:1 alpha:alpha];
//把颜色生成图片
UIImage *alphaImage = [UIImage imageWithColor:alphaColor];
//修改导航条背景图片
[self.navigationController.navigationBar setBackgroundImage:alphaImage forBarMetrics:UIBarMetricsDefault];
}
网友评论