美文网首页
ios navgationbar 颜色渐变

ios navgationbar 颜色渐变

作者: JumpSmallFlame | 来源:发表于2017-04-26 16:56 被阅读0次

    现在大多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 颜色渐变

          本文链接:https://www.haomeiwen.com/subject/ocoizttx.html