ios navgationbar 颜色渐变

现在大多app 都会有navgationbar 滑动效果,可能是因为炫酷、装逼吧!小菜鸟表示不懂!水平有限,和大家分享一下!送代码几行聊表心意!!!!

- (void)viewDidLoad {

[super viewDidLoad];

//    self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];

self.navigationController.navigationBar.translucent = NO;

//    self.automaticallyAdjustsScrollViewInsets = NO;

self.title = @"我的颜色再变吗";

self.scollView.delegate = self;

self.scollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * 3);

self.scollView.backgroundColor = [UIColor cyanColor];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

//

UIColor *color = [UIColor blueColor];

CGFloat offsetY = scrollView.contentOffset.y;

if (offsetY > 64) {

CGFloat alpha = MIN (1,(offsetY - 20)/1000);

self.navigationController.navigationBar.backgroundColor = [color colorWithAlphaComponent:alpha];

} else {

self.navigationController.navigationBar.backgroundColor = [color colorWithAlphaComponent:0];

}

}

你可能感兴趣的:(ios navgationbar 颜色渐变)