0
votes

Very simple animation:

UIView.animate(withDuration: 3, delay: 0, options: .curveLinear, animations: {
  self.imageViewA.snp.remakeConstraints({ (make) in
    make.bottom.equalTo(50);
  })
  self.layoutIfNeeded();
}, completion: {(done) in
  print(done); //called twice, both times as true
});

Animation worked fine. However, the completion block is called twice. That's fine too, I understand that I need to checked the boolean to see if it actually finished or not. Well, not only is the completion block called twice, but both time, done is TRUE.

How can I know if the animation actually completed or not?

1
The most likely cause is that the animation is being triggered twice and therefore completing twice. Add a breakpoint to the beginning of this code and have it log a message then automatically continue after.theMikeSwan
@theMikeSwan i must be tired. you were right. Can you post this as an answer so i can accept itaz2902

1 Answers

2
votes

The completion block should only be called once each time the animation completes. Make sure the animation isn't being called more than once.

Add a breakpoint to the beginning of the code you listed, edit it to log some message like "animation starting" and set it to continue after evaluation.

If you see the message more than once you can set the breakpoint to stop each time and look in the call stack to see where the calls are coming from.

If it isn't getting called twice it might be time to file a radar…