目前我正沿着路径使用CAKeyframeAnimation移动png图像30秒。有没有办法在点击按钮时在0-30秒之间停止此动态图像?
答案 0 :(得分:6)
这将删除动画......
[yourView.layer removeAllAnimations];
答案 1 :(得分:2)
嗯......你想停止动画还是只想暂停/恢复?如果你想暂停一下,那就有这样的事情:
func pause(){
pausedTime = foo.layer.convertTime(CACurrentMediaTime(), fromLayer: nil)
foo.layer.speed = 0
foo.layer.timeOffset = pausedTime!
}
func play(){
pausedTime = foo.layer.timeOffset
foo.layer.speed = 1.0
foo.layer.timeOffset = 0
let timeSincePause = foo.layer.convertTime(CACurrentMediaTime(), fromLayer: nil) - pausedTime!
foo.layer.beginTime = timeSincePause
}
答案 2 :(得分:1)
你试过吗
[view.layer removeAnimationForKey:kFrameAnimationKey];