效果:
源码很简单,直接上代码:
// gradientLayer
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 0, self.view.width, 68);
gradientLayer.position = self.view.center;
gradientLayer.colors = @[(__bridge id)[UIColor blackColor].CGColor,
(__bridge id)[UIColor whiteColor].CGColor,
(__bridge id)[UIColor blackColor].CGColor];
gradientLayer.locations = @[@0.25,@0.5,@0.75];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(1, 0);
[self.view.layer addSublayer:gradientLayer];
// unlockLabel
self.unlockLabel = [[UILabel alloc] initWithFrame:gradientLayer.bounds];
_unlockLabel.textAlignment = NSTextAlignmentCenter;
_unlockLabel.text = @"滑动来解锁 >>";
_unlockLabel.font = [UIFont boldSystemFontOfSize:28];
_unlockLabel.textColor = [UIColor colorWithWhite:0 alpha:0.8];
gradientLayer.mask = _unlockLabel.layer;
// animation
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"locations"];
animation.fromValue = @[@0,@0,@0.25];
animation.toValue = @[@0.75,@1,@1];
animation.repeatCount = MAXFLOAT;
animation.duration = 2.5f;
[gradientLayer addAnimation:animation forKey:nil];
源码已经放在GitHub:https://github.com/Fendouzhe/LRAnimations,有兴趣的欢迎下载查看,有帮助可以star,谢谢!