CATextLayer与CAGradientLayer实现文字渐变的动画效果

先上效果图=>这自己弄的gif辣眼睛 ,凑合看吧

 

1.CATextLayer的创建:

CATextLayer *textLayer = [CATextLayer layer];
textLayer.frame = CGRectMake(0, 105/2, kScreenWidth, 50);
textLayer.contentsScale = [UIScreen mainScreen].scale;
textLayer.alignmentMode = kCAAlignmentCenter;
[backView.layer addSublayer:textLayer];
textLayer.string = [self gotTextLayerAttriString:@"35个"];

CATextLayer展示文字跟Label不大一样...

 

 

 

2.创建颜色渐变层

 

CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 0, kScreenWidth, 155);
gradientLayer.colors = @[(id)[UIColor whiteColor].CGColor,
                         (id)[UIColor grayColor].CGColor,
                         (id)[UIColor whiteColor].CGColor
                        ];
gradientLayer.locations = @[@(0),@(0.25),@(0.4)];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 1);
gradientLayer.mask = textLayer;
[backView.layer addSublayer:gradientLayer];

3.让渐变层动起来

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"locations"];
animation.fromValue = @[@(0.1),@(0.1),@(0.1)];
animation.toValue = @[@(0.7),@(0.85),@(1.0)];
animation.duration = 1.5;
animation.autoreverses = YES;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
[gradientLayer addAnimation:animation forKey:nil];

 

 


 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值