iOS: Stopping a chain of Block-based animations

This can easily be done using one line of code and given you're using either [UIView animateWithDuration:animations:] or [UIView animateWithDuration:animations:completion], or both of them interchangeably.

[someView.layer removeAllAnimations]

But what if another variant of these methods is also in the mix? This method is [UIVIew animateWithDuration:delay:options:animations:completion].

What happens is that, whatever is in the completion block of this method, it still is executed right after calling [CALayer removeAllAnimations]. So the right thing to do here is always check for the value of the Boolean argument, finished. If it evaluates to True, then let the rest of the code continue. Otherwise, stop. Also, make sure to include UIViewAnimationOptionAllowUserInteraction in the options parameter.

0 comments :

Post a Comment

Hi there! Please leave your message here. Also, I may not be able to respond to your query right away. So please bear with me. Thanks. :)