更新时间:2023-12-03 16:57:34
通过转储Apple的 MKUserLocationView的动画
,我能够看到他们是如何做到的。事实证明这是 CAAnimationGroup
的用途。通过将2秒动画封装到5秒动画组中,您最终会得到2秒动画,然后是3秒延迟:
By dumping the animations of Apple's MKUserLocationView
, I was able to see how they were doing it. Turns out that this is what CAAnimationGroup
is for. By encapsulating a 2 seconds animation into a 5 seconds animation group, you'll end up with a 2 seconds animation followed by a 3 seconds delay:
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
animationGroup.duration = 5;
animationGroup.repeatCount = INFINITY;
CAMediaTimingFunction *easeOut = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale.xy"];
pulseAnimation.fromValue = @0.0;
pulseAnimation.toValue = @1.0;
pulseAnimation.duration = 2;
pulseAnimation.timingFunction = easeOut;
animationGroup.animations = @[pulseAnimation];
[ringImageView.layer addAnimation:animationGroup forKey:@"pulse"];