Why are sequential UIView animations displayed concurrently?

筅森魡賤 提交于 2019-12-13 03:10:24

问题


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?

来源:https://stackoverflow.com/questions/12250490/why-are-sequential-uiview-animations-displayed-concurrently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!