简单的滑动解锁动画

效果:



源码很简单,直接上代码:

    // 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];

源码已经放在GitHubhttps://github.com/Fendouzhe/LRAnimations,有兴趣的欢迎下载查看,有帮助可以star,谢谢!

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容