Clement Gauthier
Clement Gauthier

Reputation: 21

CATransaction completion block is called twice

I am trying to make CABasicAnimation with a CATransaction, so I can have a Completion handler. It works fine but when I quit the view Controller and come back, the completion block is called twice : Once when the animation starts and once it finishes. I only want it at the end.

The weird thong is that when I quit it and come back a second time, the completion is called 3 times and so on...

func animate() {

            CATransaction.begin()

            Animation.toValue = 0
            Animation.duration = CFTimeInterval(timerChoosenTime)
            Animation.fillMode = CAMediaTimingFillMode.forwards
            Animation.isRemovedOnCompletion = false

            CATransaction.setCompletionBlock({
                //Some cool stuff
            })

            object.add(Animation, forKey: "Animation")

            CATransaction.commit()
}

I think the program creates multiple CATransactions. The way to fix it would be to cancel the CATransaction but I found nothing about that online. Still, I am not sure. Please help me...

Upvotes: 2

Views: 293

Answers (0)

Related Questions