您的位置:首页 > 移动开发 > IOS开发

iOS 动态画圆圈

2015-07-09 10:57 309 查看
-(void)setUpAnimationLayer
{

//因为会多次点击,所以要将该图层移除,并且指针置空

[self.animationLayer
removeFromSuperlayer];

self.animationLayer =
nil;



UIBezierPath * path = [UIBezierPath
bezierPath];

//参数依次是:圆心坐标,半径,开始弧度,结束弧度
画线方向:yes为顺时针,no为逆时针

[path addArcWithCenter:CGPointMake(50,
100)
radius:50
startAngle:0
endAngle:2*M_PI
clockwise:TRUE];



CAShapeLayer * pathLayer = [CAShapeLayer
layer];
pathLayer.path = path.CGPath;
pathLayer.strokeColor = [[UIColor
blueColor]CGColor];//画线颜色
pathLayer.fillColor = [[UIColor
redColor]CGColor];//填充颜色

pathLayer.lineJoin =
kCALineJoinRound;
pathLayer.lineWidth =
6.0f;
[self.view.layer
addSublayer:pathLayer];

[self
setAnimationLayer:pathLayer];//把pathLayer赋给属性animationLayer
}

- (IBAction)btnClick:(id)sender {

[self
setUpAnimationLayer];



[self.animationLayer
removeAllAnimations];//每次将之前的动画都清除了



// keyPath = strokeEnd
动画的fromValue = 0,toValue = 1
表示
这里我们分3个点说明动画的顺序 strokeEnd从结尾开始清除
首先整条路径先清除后2/3,接着清除1/3
效果就是正方向画出路径

CABasicAnimation *pathAnimation = [CABasicAnimation
animationWithKeyPath:@"strokeEnd"];
pathAnimation.duration =
10.0;
pathAnimation.fromValue =
@(0);
pathAnimation.toValue =
@(1);
[self.animationLayer
addAnimation:pathAnimation
forKey:@"strokeEnd"];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: