Hi I have simple CAShapeLayer animation
let ballFrameAnimation = CAKeyframeAnimation()
aBall.removeFromSuperlayer()
self.view.layer.addSublayer(aBall)
ballFrameAnimation.keyPath = "position"
ballFrameAnimation.duration = 3.0
ballFrameAnimation.calculationMode = kCAAnimationDiscrete
ballFrameAnimation.fillMode = kCAFillModeForwards
ballFrameAnimation.isRemovedOnCompletion = true
ballFrameAnimation.delegate = self
with a callback to keeps it repeating
func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
let name = anim.value(forKey: "name") as? String
if name == "form" {
attachAnimation()
forwardDirection = !forwardDirection
}
However this persists and loops in the background ( at high speed) even when I pop the viewcontroller off the stack. It also shows a memory leak as well on instruments.
@IBAction func unwindDismiss(_ sender: Any) {
aBall.removeAnimation(forKey: "ballAnimation")
aBall.removeFromSuperlayer()
navigationController?.popToRootViewController(animated:true)
dismiss(animated: true, completion: nil)
}