Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: How can I set an action to occur at the completion of a CAKeyFrameAnimation

I'm using a CAKeyFrameAnimation in a similar manner to how it's used on this page. I'm trying to have an action occur at the end of the animation, but I'm not sure how I can go about doing that. I looked through the CAKeyFrameAnimation docs and didn't see anything about a completionHandler or anything, and the only thing I can think to do is to set a timer for the animation length and handle everything after that. I figure there must be some better way to get notified that the animation has completed, but I haven't been able to find a better solution.

like image 756
NumberOneRobot Avatar asked Dec 01 '22 15:12

NumberOneRobot


1 Answers

Swift

Use CATransaction.setCompletionBlock as below.

CATransaction.begin()
CATransaction.setCompletionBlock({
    view.isHidden = true
})

let animation = CAKeyframeAnimation(keyPath: "position")
animation.path = path

view.layer.add(animation, forKey: "moveIn")

CATransaction.commit()
like image 68
Jeff Gu Kang Avatar answered Dec 07 '22 01:12

Jeff Gu Kang