zoukankan      html  css  js  c++  java
  • 通过CAGradientLayer类实现色度差动画

    #import "ViewController.h"
    
    @interface ViewController ()
    {
        CAGradientLayer *_gradientLayer;
    }
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
     
        UIImageView *_imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1"]];
        _imageView.center       = self.view.center;
        [self.view addSubview:_imageView];
        
        _gradientLayer            = [CAGradientLayer layer];
        _gradientLayer.frame      = _imageView.bounds;
        
        /**设置渐变方向*/
        _gradientLayer.startPoint = CGPointMake(0, 0);
        _gradientLayer.endPoint   = CGPointMake(0, 1);
        
        /**设置颜色*/
        _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/255.0
                                                                    green:arc4random()%255/255.0
                                                                     blue:arc4random()%255/255.0
                                                                    alpha:1.0].CGColor
                                       ];
        
    }

  • 相关阅读:
    JQuery学习四(过滤选择器)
    JQuery学习三(隐式迭代和节点遍历)
    JQuery学习二(获取元素控件并控制)
    JQuery学习一
    Dom中select练习
    DOM动态操纵控件案例
    DOM学习控件定位和案例
    DOM案例五星评分控件
    DOM动态增加控件
    DOM用TagName操作标签
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4384599.html
Copyright © 2011-2022 走看看