1
我正在嘗試創建一個圓形條,例如你可以在iOS上使用本機攝像機拍攝按鈕時找到一個圓形條。CABasicAnimation + UIBezierPath
沿着動畫創建一個圓圈,一旦完成,就會「自然」移除。
我嘗試下面的代碼:
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.lapseBtnOutlet.center.x, self.lapseBtnOutlet.center.y) radius:28 startAngle:2*M_PI*0-M_PI_2 endAngle:2*M_PI*1-M_PI_2 clockwise:YES].CGPath;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor whiteColor].CGColor;
circle.lineWidth = 2.0;
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = self.lapseInterval;
animation.removedOnCompletion = NO;
animation.fromValue = @(0);
animation.toValue = @(1);
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
[circle addAnimation:animation forKey:@"drawCircleAnimation"];
但現在我的問題是,我不知道如何「刪除」從開始到結束的線。
我嘗試使用autoreverse屬性,但它從開始到結束從頭到尾移除圓。有任何想法嗎?
它工作得很好!謝謝你的幫助! :) – Pataquer 2014-12-06 05:34:00