美文网首页iOS常用
iOS 动画之光条滑动

iOS 动画之光条滑动

作者: 画舫烟中浅 | 来源:发表于2021-02-01 15:37 被阅读0次

项目中需要实现一个打光的动画效果,先看下效果图

图像.gif

录的视频转成gif图,不是很清晰。效果在21点跟快速开始图片上。

实现代码如下:

//动效 21 dian
UIImageView *twoOneImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, gameSize.width, gameSize.height)];
twoOneImageView.image = ImageNamed(gameImageName);
[_gameButton addSubview:twoOneImageView];
// 初始化渐变层
self.twoOneRotColorLayer = [CAGradientLayer layer];
self.twoOneRotColorLayer.frame = twoOneImageView.frame;
self.twoOneRotColorLayer.position = twoOneImageView.center;
[_gameButton.layer addSublayer:self.twoOneRotColorLayer];

//颜色数组
self.twoOneRotColorLayer.colors = @[(__bridge id)[kColorffffff colorWithAlphaComponent:0.1].CGColor,(__bridge id)[kColorffffff colorWithAlphaComponent:0.3].CGColor,(__bridge id)[kColorffffff colorWithAlphaComponent:0.1].CGColor];
//颜色分层
self.twoOneRotColorLayer.locations = @[@(- 0.2),@(- 0.1),@(0)];
// 渐变方向
self.twoOneRotColorLayer.startPoint = CGPointMake(0, 0.1);
self.twoOneRotColorLayer.endPoint = CGPointMake(1, 0.9);
self.twoOneRotColorLayer.mask = twoOneImageView.layer;

//动效 kuaisukaishi
UIImageView *quickStartImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, taskSize.width, taskSize.height)];
quickStartImageView.image = ImageNamed(taskImageName);
[_taskButton addSubview:quickStartImageView];
// 初始化渐变层
self.quickStartColorLayer = [CAGradientLayer layer];
self.quickStartColorLayer.frame = quickStartImageView.frame;
self.quickStartColorLayer.position = quickStartImageView.center;
[_taskButton.layer addSublayer:self.quickStartColorLayer];

//颜色数组
self.quickStartColorLayer.colors = @[(__bridge id)[kColorffffff colorWithAlphaComponent:0.1].CGColor,(__bridge id)[kColorffffff colorWithAlphaComponent:0.3].CGColor,(__bridge id)[kColorffffff colorWithAlphaComponent:0.1].CGColor];
//颜色分层
self.quickStartColorLayer.locations = @[@(- 0.2),@(- 0.1),@(0)];
// 渐变方向
self.quickStartColorLayer.startPoint = CGPointMake(0, 0.9);
self.quickStartColorLayer.endPoint = CGPointMake(1, 0.1);
self.quickStartColorLayer.mask = quickStartImageView.layer;


self.locationAnimation = [CABasicAnimation animationWithKeyPath:@"locations"];
self.locationAnimation.fromValue = @[@(-0.2), @(-0.1),@(0)] ;
self.locationAnimation.toValue = @[@(1.0),@(1.1),@(1.2)] ;
self.locationAnimation.duration = 2.0 ;

self.colorTimer = [NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(gradientLayerEvent) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.colorTimer forMode:NSDefaultRunLoopMode];


#pragma mark --- 定时器事件
-(void)gradientLayerEvent{
   // 动效
   if (self.locationAnimation) {
      [self.twoOneRotColorLayer addAnimation:self.locationAnimation forKey:nil];
      [self.quickStartColorLayer addAnimation:self.locationAnimation forKey:nil];
  }
}

个人觉得写的不是很好,希望大佬指出不足之处。以供学习交流。

相关文章

  • iOS 动画之光条滑动

    项目中需要实现一个打光的动画效果,先看下效果图 录的视频转成gif图,不是很清晰。效果在21点跟快速开始图片上。 ...

  • iOS 手势返回

    iOS 手势返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

  • iOS 全屏返回

    iOS 全屏返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

  • iOS 全屏手势返回

    BBGestureBack BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势...

  • iOS 右滑返回

    BBGestureBack BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势...

  • BBGestureBack 手势返回

    BBGestureBack BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势...

  • iOS-动画相关

    本篇涵盖各种直播动画,跳转,过渡动画等. 1.分享iOS中实现navigationController全屏手势滑动...

  • iOS 右滑返回

    iOS 右滑返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

  • iOS 侧滑返回

    iOS 侧滑返回 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流App...

  • iOS 侧滑返回详解

    iOS 侧滑返回详解 BBGestureBack iOS 全屏手势返回 滑动返回 pop 动画效果 这种手势主流A...

网友评论

    本文标题:iOS 动画之光条滑动

    本文链接:https://www.haomeiwen.com/subject/pfajtltx.html