//bgView
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, self.view.height-120.0f, self.view.width, 60.0f)];
bottomView.backgroundColor = [UIColor grayColor];
[self.view addSubview:bottomView];
CAGradientLayer *gradinetLayer = [CAGradientLayer layer];
[bottomView.layer addSublayer:gradinetLayer];
gradinetLayer.frame = CGRectMake(0, 10, bottomView.width, 30);
gradinetLayer.startPoint = CGPointMake(0, 0.5);//要确定startPoint
gradinetLayer.endPoint = CGPointMake(1, 0.5);//确定endPoint,这二者共同决定动画滚动的方向
gradinetLayer.colors = @[
(__bridge id)[UIColor blackColor].CGColor,
(__bridge id)[UIColor whiteColor].CGColor,
(__bridge id)[UIColor blackColor].CGColor
];
gradinetLayer.locations = @[@0.25,@0.5,@0.75];
// 添加部分
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"locations"];
basicAnimation.fromValue = @[@0, @0, @0.25];
basicAnimation.toValue = @[@0.75, @1, @1];
basicAnimation.duration = 2.0;
basicAnimation.repeatCount = HUGE;
[gradinetLayer addAnimation:basicAnimation forKey:nil];
本文介绍如何使用CAGradientLayer创建动态渐变效果,并通过CABasicAnimation实现动画滚动,适用于iOS应用开发。
929

被折叠的 条评论
为什么被折叠?



