I have a strange bug that I've found in the app I'm working on. Before I get into the details I'll state my questions which are
1 - Why could a UIView animation completion block not be called
2 - Why would the UIView animation completion block then be called after a modal view is presented?
I have a series of UIView animations that begin after the view controller appears. They have completion blocks. The vast majority of the time the animation completion blocks get called. But every so often the app gets into a state where the completions blocks don't get called.
Furthermore, when I present a new view controller modally from the current view controller, the animation completion blocks that weren't called before all get called.
Once the app is in this state, the animation completion blocks never get called again, except when I present the modal view again.
My animation block is basically this:
int i = 0;
for (UIView *view in self.cellImageViews)
{
[UIView animateWithDuration:CELL_ANIMATION_DISMISS_DURATION
delay:(i)*CELL_ANIMATION_STAGGER_INTERVAL
options:UIViewAnimationOptionCurveEaseIn
animations:^{
view.transform = CGAffineTransformTranslate(view.transform, 0, CELL_ANIMATION_DISMISS_TRANSLATION);
} completion:^(BOOL finished) {
NSLog(@"Animation Completed: i:%d, finished:%d, count%d",i,finished,[self.oldCellImageViews count])
if(finished && (i == ([self.cellImageViews count]-1)))
{
NSLog(@"if statement passed");
// My completion block stuff goes here
}
}
];
i++;
}