UIView 添加闪烁的渐变光

Posted DHUI

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UIView 添加闪烁的渐变光相关的知识,希望对你有一定的参考价值。

CGRect gradientRect=CGRectMake(- imageView3.bounds.size.width*1.5, 0, 4 * imageView3.bounds.size.width, imageView3.bounds.size.height);
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    gradientLayer.frame =gradientRect;
    gradientLayer.colors = @[(id)hexColor(bb975e).CGColor,(id)[UIColor whiteColor].CGColor,(id)hexColor(bb975e).CGColor];
    gradientLayer.locations = @[@(0.25),@(0.5),@(0.75)];
    gradientLayer.startPoint = CGPointMake(0, 0.5);
    gradientLayer.endPoint = CGPointMake(1, 0.5);
    gradientLayer.position = CGPointMake(imageView3.bounds.size.width*0.5, imageView3.bounds.size.height/2.0);
    [imageView3.layer addSublayer:gradientLayer];
    
    CALayer *maskLayer = [CALayer layer];
    maskLayer.frame =CGRectOffset(imageView3.bounds, imageView3.bounds.size.width*1.5, 0);
    maskLayer.contents = (__bridge id)([UIImage imageNamed:@"launchImage3"].CGImage);
    gradientLayer.mask = maskLayer;
    
    CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"locations"];
    fadeAnim.fromValue = @[@(0.0),@(0.0),@(0.25)];
    fadeAnim.toValue = @[@(0.75),@(1.0),@(1.0)];
    fadeAnim.duration=2;
    fadeAnim.repeatCount = CGFLOAT_MAX;
    [gradientLayer addAnimation:fadeAnim forKey:nil];

 

以上是关于UIView 添加闪烁的渐变光的主要内容,如果未能解决你的问题,请参考以下文章

渐变不填充 IBDesignable UIView

覆盖javascript以消除闪烁

将渐变应用到 UIView 的一个角

在 UIView 上应用渐变不起作用

滚动后 UITableViewCell 内的 UIView 中的渐变发生了变化

带有渐变和阴影的 UIView