iOS 动画 CAGradientLayer、 CABasicAnimation~demo

//联系人:石虎 QQ:1224614774 昵称:嗡嘛呢叭咪哄

一、概念


/**

   1.此方法很简单,有操作视图和方法,动画效果参考~直接拷贝就可以实现

   2. 图片下面有, 代码可以任意修改变化不同的颜色显示,

   3.GIF 图请看简书:https://www.jianshu.com/p/238835eab372

 */

GIF图:

               iPhone X     




二、代码实现


//  ViewController.m

//  滑动解锁动画~demo

//

//  Created by joyshow on 2018/1/20.

//  Copyright © 2018年 石虎. All rights reserved.

//


#import "ViewController.h"


#define SHPageCount  2

#define KMainScreenH [UIScreen mainScreen].bounds.size.height

#define kMainScreenW [UIScreen mainScreen].bounds.size.width


@interface ViewController ()<UIScrollViewDelegate>



//解锁 label

@property (nonatomic,strong)UILabel *unlockLabel;


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    [selfanimationUnlockLabel];

}


#pragma mark - 设置所有动画解锁方法

#pragma mark -

- (void)animationUnlockLabel

{

    

    // gradientLayer

    CAGradientLayer *gradientLayer = [CAGradientLayerlayer];

    gradientLayer.frame = CGRectMake(0, 0, kMainScreenW, KMainScreenH);

    gradientLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,

                             (__bridge id)[UIColor yellowColor].CGColor,

                             (__bridge id)[UIColor purpleColor].CGColor];

    gradientLayer.locations = @[@0.25,@0.5,@0.75];

    gradientLayer.startPoint = CGPointMake(0, 0);

    gradientLayer.endPoint = CGPointMake(1, 0);

    [self.view.layeraddSublayer:gradientLayer];

    

    // 初始化 unlockLabel

    self.unlockLabel = [[UILabelalloc]initWithFrame:gradientLayer.bounds];

    gradientLayer.mask = _unlockLabel.layer;

    [self.viewaddSubview:_unlockLabel];

    

    //执行动画 animation

    CABasicAnimation *animation = [CABasicAnimationanimationWithKeyPath:@"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];

    

}


@end


谢谢!!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值