IOS实现随着页面滑动改变导航条透明度的方法
1.实现代理UIScrollViewDelegate
2.
#pragma mark -- UIScrollDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (scrollView.contentOffset.y < 0) {
self.scrollView.contentOffset = CGPointMake(0, 0);
}
if (scrollView.contentOffset.y > 100) {
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [DHCText3Color colorWithAlphaComponent:(scrollView.contentOffset.y/100)],NSFontAttributeName:[UIFont systemFontOfSize:15]}];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithPatternImage:[self getImageWithAlpha:scrollView.contentOffset.y/100]];
_lineView = [self getLineViewInNavigationBar:self.navigationController.navigationBar];
_lineView.hidden = NO;
}
if (scrollView.contentOffset.y < 100) {
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [DHCText3Color colorWithAlphaComponent:(scrollView.contentOffset.y/100)],NSFontAttributeName:[UIFont systemFontOfSize:15]}];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithPatternImage:[self getImageWithAlpha:scrollView.contentOffset.y/100]];
_lineView = [self getLineViewInNavigationBar:self.navigationController.navigationBar];
_lineView.hidden = YES;
}
}
网友评论