All you need to do is add a BOOL
property that indicates whether or not the animation should keep looping. Then change that animation block to something like:
[UIView transitionWithView:self.sendButton
duration:0.6f
options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionAllowUserInteraction
animations:^{
[self.sendButton setImage:toImage forState:UIControlStateNormal];
} completion:^(BOOL finished){
if (self.repeatAnimations)
{
[self performSelector:@selector(animateArrows) withObject:nil afterDelay:0.0];
}
}];
The reason you need to perform this check is that you have an otherwise infinite loop that is retaining self
. Once you leave this loop your view controller will be dealloc
'd.