• 动态闪字


    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

  • 相关阅读:
    android 4种启动模式
    android定位
    android GestureDetector 手势基础
    Android 软键盘盖住输入框的问题
    Android Fragment应用实战,使用碎片向ActivityGroup说再见
    Android Fragment完全解析,关于碎片你所需知道的一切
    setImageResource和setBackgroundResource的區別
    【Android面试】Android面试题集锦 (陆续更新)(最新2012-6-18) eoe上看到的
    Android内存性能优化(内部资料总结)
    关于BFC
  • 原文地址:https://www.cnblogs.com/mudy/p/4931547.html
Copyright © 2020-2023  润新知