Choppy UIView动画

时间:2011-11-15 00:49:22

标签: ios core-animation uiviewanimation quartz-core

我使用UIView动画在屏幕周围随机动画5个方块(UIButtons)。根据用户的选择,可以看到2到5个方格。当只有2个可见时,其他三个隐藏值设置为YES,所以它们实际上仍然是动画(对吗?),它们只是不可见。但是当只有2个可见时,动画是平滑的,但当所有五个都可见时,动画会变得不稳定。我不确定如何描述它,因为方块仍然以正确的速度移动并移动到正确的点;波涛汹涌并不可怕,只是非常糟糕,值得注意。有没有办法摆脱它?这是我用来为正方形设置动画的代码:

编辑:将动画更改为阻止:

[UIView animateWithDuration:animationSpeed 
                              delay:0 
                            options:UIViewAnimationOptionCurveLinear 
                         animations:^{
                             view.center = destPoint;
                         }
                         completion:^(BOOL finished){
                             if([view isEqual:squareThree])
                                 [self moveBadGuys];
                         }
         ];

/*for(UIButton* button in squareArray) {
    if(!shouldMove)
        return;

    [UIView beginAnimations:@"b" context:nil];
    [UIView setAnimationDuration:animationSpeed];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    view.center = destPoint;
    [UIView commitAnimations];
}*/

编辑:呈现这个的视图是三个带有

的UIViewController的堆栈中的第三个
ViewController* controller = [[[ViewController alloc] init] autorelease];
[self presentModalViewController:controller animated:NO];

这种呈现观点的方式是否会耗尽记忆力?

2 个答案:

答案 0 :(得分:2)

有一些事情可以导致这种情况。它总是归结为内容的复杂程度。此外,模拟器在处理动画方面可能非常糟糕,因此请确保您在真实硬件上进行测试。

按钮上有大图像吗?按钮是否投射阴影?那些东西可以减慢速度。

另外 - 使用基于块的动画。不是旧的begin-commit方法。

答案 1 :(得分:0)

不完全确定为什么它很慢,但你尝试过不同的嵌套方式吗?

if(!shouldMove)
    return;

[UIView beginAnimations:@"b" context:nil];
[UIView setAnimationDuration:animationSpeed];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

for(UIButton* button in squareArray) {
    view.center = destPoint;
}

[UIView commitAnimations];

确实(几乎 - !shouldMove案例中的逻辑略有不同,但这是一个不同的故事)同样,但是以更清洁的方式。