I've written some code that moves some objects around on the screen in sequence. As each object finishes moving, the next starts.
The code is structured similarly to this:
Model:
moveObject
{
// Code to move the object
...
[delegate moved:self];
}
Delegate:
moved:(MyClass *)o
{
UIView* v = [self viewForObject:o];
[UIView animateWithDuration:1.0
animations:^{
[v setCenter: [model center]];
}
completion:^(BOOL finished){
// Move object
[model moveObject];
}];
}
Although the code seems to run okay, what happens on screen is that the animations are grouped into batches: a large number all happen at once, and then another group all begin.
If I place a breakpoint on the line [model moveObject];
then it is hit several times with finished
set to true
without any of the animations being displayed on screen. Then, occasionally, finished
will be set to false
, and after I let debugging continue, all the animations will be carried out on-screen.
Edit:
However, if I change the code to occasionally not move an object when moveObject is called, but instead return without action, and wait the user to move an object, (and thus calling back into this code via the delegate's moved:
selector), then the short strings of animations occur sequentially.
i.e. The problem appears to only occur when the code is in an infinite loop.
What's going wrong?