0

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?

Rich
  • 7,348
  • 4
  • 34
  • 54
  • How is your `moveObject` method determining what model to move? Are you calling move object from somewhere else? Like a loop? Unrelated: can you even name an object "Object" without clashing to the internal classes och Objective C? – David Rönnqvist Sep 03 '12 at 16:39
  • @DavidRönnqvist I've simplified the code quite a lot. Move object is called once from elsewhere, which starts off the chain of animations. (I don't think it matters how moveObject picks which model it moves.) – Rich Sep 03 '12 at 16:44

0 Answers0