Ios 多次呼叫同一个CABasicAnimation
我目前有一个黑客的工作,但不是理想的。我想在第一次调用同一动画结束之前多次调用它。我正在使用一个Ios 多次呼叫同一个CABasicAnimation,ios,swift,animation,core-animation,cabasicanimation,Ios,Swift,Animation,Core Animation,Cabasicanimation,我目前有一个黑客的工作,但不是理想的。我想在第一次调用同一动画结束之前多次调用它。我正在使用一个delay函数,因为我不知道如何正确地实现我想要的核心动画。关于如何删除这里的delay函数调用并使用核心动画方法/属性来获得相同的结果,您有什么想法吗 这是我的动画: func animateCircle() { // The circle in its smallest size. let circlePath1 = UIBezierPath(arcCenter: self.cen
delay
函数,因为我不知道如何正确地实现我想要的核心动画。关于如何删除这里的delay
函数调用并使用核心动画方法/属性来获得相同的结果,您有什么想法吗
这是我的动画:
func animateCircle() {
// The circle in its smallest size.
let circlePath1 = UIBezierPath(arcCenter: self.center, radius: CGFloat(3), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
// The circle in its largest size.
let circlePath2 = UIBezierPath(arcCenter: self.center, radius: CGFloat(60), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
// Configure the layer.
let shapeLayer = CAShapeLayer()
let green = UIColor(red: 0, green: 222, blue: 183, alpha: 100)
shapeLayer.strokeColor = green.CGColor
shapeLayer.fillColor = green.CGColor
// This is the path that's visible when there'd be no animation.
shapeLayer.path = circlePath1.CGPath
self.layer.addSublayer(shapeLayer)
// Animate the path.
let pathAnimation = CABasicAnimation(keyPath: "path")
pathAnimation.fromValue = circlePath1.CGPath
pathAnimation.toValue = circlePath2.CGPath
// Animate the alpha value.
let alphaAnimation = CABasicAnimation(keyPath: "opacity")
alphaAnimation.fromValue = 1
alphaAnimation.toValue = 0
// We want both animations to run together perfectly, so we
// put them into an animation group.
let group = CAAnimationGroup()
group.animations = [pathAnimation, alphaAnimation]
group.duration = 2.4
group.repeatCount = FLT_MAX
// Add the animation to the layer.
shapeLayer.addAnimation(group, forKey:"sonar")
}
这就是我调用函数的方式:
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
animateCircle()
delay(0.8) {
self.animateCircle()
}
delay(1.6) {
self.animateCircle()
}
}
注意
延迟的两种用法。我不想用这些。有什么想法吗?你可以试试CAKeyframeAnimation@LeoDabus谢谢回复!我刚开始使用核心动画,我想我以前见过。你能为这篇文章或一篇好文章提供一个答案吗?objc.io有一个-includeCAKeyframeAnimation
。你可以试试CAKeyframeAnimation@LeoDabus谢谢回复!我刚开始使用核心动画,我想我以前见过。你能为这篇文章或一篇好文章提供答案吗?objc.io有一个-includeCAKeyframeAnimation
。