ios - CABasicAnimation + UIBezierPath
<p><p>我正在尝试创建一个圆形条,当您进行延时摄影时,您可以在 iOS 原生相机的录制按钮周围找到它。</p>
<p>沿着动画创建一个圆圈,一旦完成,就会“自然”地再次删除。</p>
<p>我尝试了下一个代码:</p>
<pre><code>CAShapeLayer *circle = ;
circle.path = .CGPath;
circle.fillColor = .CGColor;
circle.strokeColor = .CGColor;
circle.lineWidth = 2.0;
CABasicAnimation *animation = ;
animation.duration = self.lapseInterval;
animation.removedOnCompletion = NO;
animation.fromValue = @(0);
animation.toValue = @(1);
animation.timingFunction = ;
;
</code></pre>
<p>但我现在的问题是我不知道如何从头到尾“删除”这条线。</p>
<p>我尝试使用 autoreverse 属性,但它从头到尾删除了圆,而不是从头到尾。有任何想法吗? </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您需要将 <code>strokeStart</code> 的动画从 0 变为 1,当动画结束时,移除形状图层。 </p>
<pre><code>- (void)viewDidLoad {
;
;
;
}
-(void)animateProperty:(NSString *) prop {
if (! self.circle) {
self.circle = ;
self.circle.path = .CGPath;
self.circle.fillColor = .CGColor;
self.circle.strokeColor = .CGColor;
self.circle.lineWidth = 2.0;
;
}
CABasicAnimation *animation = ;
animation.delegate = ()? self : nil;
animation.duration = 1;
animation.removedOnCompletion = NO;
animation.fromValue = @0;
animation.toValue = @1;
;
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
;
self.circle = nil;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - CABasicAnimation + UIBezierPath,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/27323006/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/27323006/
</a>
</p>
页:
[1]