iOS专题资源__UI专题轮子iOS Developer

圆环旋转加载动画

2017-01-09  本文已影响150人  千年积木

给需要的朋友,思路还是比较简单,代码比较直接,没有封装,复制粘贴即可看到效果。

屏幕快照 2017-01-09 下午4.00.58.png

<pre>

pragma mark- gradientlayer 与 gradientlayer 之间颜色过渡

colour0 = colours[0];
colour1 = colours[1];
colour2 = colours[2];
colour3 = colours[3];


CALayer * layer0 = [CALayer layer];
layer0.frame = CGRectMake(20, 150, 150, 150);
[self.view.layer addSublayer:layer0];

CALayer * layer1 = [CALayer layer];
layer1.frame = CGRectMake(0, 0, 150, 150);
[layer0 addSublayer:layer1];

pragma mark-4个gradientlayer颜色渐变

CAGradientLayer * gradientlayer1 = [CAGradientLayer layer];
gradientlayer1.frame = CGRectMake(0, 0, 75, 75);

gradientlayer1.colors = @[(__bridge id)colour0.CGColor,
                          (__bridge id)colour1.CGColor];

gradientlayer1.startPoint = CGPointMake(1, 0);
gradientlayer1.endPoint = CGPointMake(0, 1);


CAGradientLayer * gradientlayer2 = [CAGradientLayer layer];
gradientlayer2.frame = CGRectMake(0, 75, 75, 75);

gradientlayer2.colors = @[(__bridge id)colour1.CGColor,
                          (__bridge id)colour2.CGColor];

gradientlayer2.startPoint = CGPointMake(0, 0);
gradientlayer2.endPoint = CGPointMake(1,1);

CAGradientLayer * gradientlayer3 = [CAGradientLayer layer];
gradientlayer3.frame = CGRectMake(75, 75, 75, 75);

gradientlayer3.colors = @[(__bridge id)colour2.CGColor,
                          (__bridge id)colour3.CGColor];

gradientlayer3.startPoint = CGPointMake(0, 1);
gradientlayer3.endPoint = CGPointMake(1, 0);

CAGradientLayer * gradientlayer4 = [CAGradientLayer layer];
gradientlayer4.frame = CGRectMake(75, 0, 75, 75);

gradientlayer4.colors = @[(__bridge id)colour3.CGColor,
                          (__bridge id)[UIColor whiteColor].CGColor];

gradientlayer4.startPoint = CGPointMake(1, 1);
gradientlayer4.endPoint = CGPointMake(0, 0);

[layer1 addSublayer:gradientlayer1];
[layer1 addSublayer:gradientlayer2];
[layer1 addSublayer:gradientlayer3];
[layer1 addSublayer:gradientlayer4];

pragma mark- 把下面代码注释掉,就可以看到4个人gradientlayer颜色过渡效果

//路径
UIBezierPath * beizierPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(75, 75) radius:70 startAngle: -M_PI/2 endAngle:M_PI*2 -M_PI/2 clockwise:YES];
CAShapeLayer * shaperLayer = [CAShapeLayer layer];
shaperLayer.lineCap = kCALineCapRound;
shaperLayer.fillColor = [UIColor clearColor].CGColor;
shaperLayer.strokeColor = [UIColor redColor].CGColor;
shaperLayer.lineWidth = 5.0;
shaperLayer.strokeStart = 0.01;
shaperLayer.strokeEnd = 0.99;
shaperLayer.path = beizierPath.CGPath;
layer1.mask = shaperLayer;


//添加动画
CABasicAnimation * basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
basicAnimation.duration = 1;
basicAnimation.fromValue = @0.0;
basicAnimation.toValue = @(M_PI*2);
basicAnimation.repeatCount = HUGE_VAL;

[layer0 addAnimation:basicAnimation forKey:@"transform.rotation.z"];

}

pragma mark- 获取颜色

上一篇下一篇

猜你喜欢

热点阅读