通过CAGradientLayer类实现色度差动画

#import "ViewController.h"

@interface ViewController ()
{
CAGradientLayer *_gradientLayer;
}
@end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad]; UIImageView *_imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];
_imageView.center = self.view.center;
[self.view addSubview:_imageView]; _gradientLayer = [CAGradientLayer layer];
_gradientLayer.frame = _imageView.bounds; /**设置渐变方向*/
_gradientLayer.startPoint = CGPointMake(, );
_gradientLayer.endPoint = CGPointMake(, ); /**设置颜色*/
_gradientLayer.colors = @[ (__bridge id)[UIColor clearColor].CGColor,
(__bridge id)[UIColor redColor].CGColor
]; /**设置颜色分割点*/
_gradientLayer.locations = @[@(0.5),@(1.0f)]; [_imageView.layer addSublayer:_gradientLayer]; [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerEvent) userInfo:nil repeats:YES]; }
- (void)timerEvent
{
_gradientLayer.colors = @[ (__bridge id)[UIColor clearColor].CGColor,
(__bridge id)[UIColor colorWithRed:arc4random()%/255.0
green:arc4random()%/255.0
blue:arc4random()%/255.0
alpha:1.0].CGColor
]; }

通过CAGradientLayer类实现色度差动画

上一篇:RDLC报表系列(一) 简单的动态数据绑定和配置


下一篇:CA*Layer(CATransformLayer--CAGradientLayer)