码迷,mamicode.com
首页 > 其他好文 > 详细

动态闪字

时间:2015-11-02 23:03:20      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:

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

 

动态闪字

标签:

原文地址:http://www.cnblogs.com/mudy/p/4931547.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!