美文网首页
简单的滑动解锁动画

简单的滑动解锁动画

作者: nongjiazhen | 来源:发表于2019-11-25 16:28 被阅读0次

    效果:

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

        // 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,谢谢!

    相关文章

      网友评论

          本文标题:简单的滑动解锁动画

          本文链接:https://www.haomeiwen.com/subject/hcmogftx.html