• 动态闪字


    http://www.tuicool.com/articles/RZBFBn

    http://www.devtalking.com/articles/calayer-animation-gradient-animation/

    直接粘贴代码了:OC的,上边有swift的:

    //

    //  ViewController.m

    //  oc

    //

    //  Created by mudy on 15/11/2.

    //  Copyright © 2015年 mudy. All rights reserved.

    //

    #import "ViewController.h"

    @interface ViewController ()

    @property (weak, nonatomic) IBOutlet UILabel *textLabel;

    @property (weak, nonatomic) IBOutlet UIView *backgroundView;

    @property (nonatomic,strong)CAGradientLayer *gradientLayer;

    @property (nonatomic,strong)NSString *text;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.gradientLayer = [[CAGradientLayer alloc]init];

        self.text = @"梦想还是要有的,万一实现了呢";

        self.gradientLayer.bounds = CGRectMake(0, 0, self.backgroundView.frame.size.width, self.backgroundView.frame.size.height);

        self.gradientLayer.position = CGPointMake(self.backgroundView.frame.size.width/2, self.backgroundView.frame.size.height/2);

        self.gradientLayer.startPoint = CGPointMake(0, 0.5);

        self.gradientLayer.endPoint = CGPointMake(1, 0.5);

        

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

                                      (__bridge id)[UIColor yellowColor].CGColor,

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

        

        self.gradientLayer.locations = @[@0.2, @0.5, @0.8];

        [self.backgroundView.layer addSublayer:self.gradientLayer];

        

        // Do any additional setup after loading the view, typically from a nib.

    }

    -(void)viewDidAppear:(BOOL)animated{

        self.textLabel.text = self.text;

        self.gradientLayer.mask = self.textLabel.layer;

        [self gradinetAnimate];

    }

    -(void)gradinetAnimate{

        

        CABasicAnimation *gradient = [CABasicAnimation animationWithKeyPath:@"locations"];

    //    let gradient = CABasicAnimation(keyPath: "locations")

        gradient.fromValue = @[@0, @0, @0.25];

        gradient.toValue = @[@0.75, @1, @1];

        gradient.duration = 4.5;

        gradient.repeatCount = HUGE;

        [self.gradientLayer addAnimation:gradient forKey:nil];

        

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    SQL Server常用到的几个设置选项
    动态加载母版页
    Sql查询技巧
    【WP7】关于磁贴的使用
    ashx,页面一般情况下不能方法session,必须添加两个接口。才能访问session。 狼
    悟头javascript学习笔记 狼
    IIS处理简介, IHttpHandler ,IHttpModel 狼
    在IIS下,不能执行exe文件解决办法。 狼
    给Ubuntu右键快捷菜单添加终端栏目
    VC 单文档程序 隐藏程序及任务栏图标
  • 原文地址:https://www.cnblogs.com/mudy/p/4931547.html
Copyright © 2020-2023  润新知