在view的layer上添加一个渐变的layer
CAGradientLayer *layer = [CAGradientLayer new];
//colors存放渐变的颜色的数组
layer.colors=@[(__bridge id)[UIColor redColor].CGColor,(__bridge id)[UIColor whiteColor].CGColor];
/*** 起点和终点表示的坐标系位置,(0,0)表示左上角,(1,1)表示右下角 */
layer.startPoint = CGPointMake(0.4, 0.4);
layer.endPoint = CGPointMake(0.4, 0.41);
layer.frame = self.bounds;
self.color_layer = layer;
[self.layer addSublayer:self.color_layer];
渐变过程加一个动画
CABasicAnimation *gradient = [CABasicAnimation animationWithKeyPath:@"locations"];
gradient.duration = 4.0;
// gradient.fillMode = kCAFillModeForwards;
gradient.fromValue = @[@(0),@(0)];
gradient.toValue = @[@(0.2),@(1)];
gradient.removedOnCompletion = NO;
gradient.repeatCount = 1;
[self.color_layer addAnimation:gradient forKey:nil];
网友评论