0
votes

I use a UIView animation to randomly animate 5 squares (UIButtons) around the screen. Depending on a user selection, there are anywhere from 2 to 5 squares visible. When only 2 are visible, the other three's hidden values get set to YES, so they are actually still animating (right?), they just aren't visible. But when only 2 are visible, the animation is smooth, but when all five are visible, the animation gets choppy. I'm not really sure how to describe it, because the squares are still moving at the correct speed and moving to the correct points; the choppiness isn't terrible, just bad enough to be noticeable. Is there any way to get rid of it? This is the code I use to animate the squares:

Edit: changed animations to block:

[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];
}*/

Edit: the view presenting this is the third in a stack of three UIViewController presented with

ViewController* controller = [[[ViewController alloc] init] autorelease];
[self presentModalViewController:controller animated:NO];

Does this way of presenting views eat up memory?

2
Could it be because you are low in memory?SimplyKiwi
I was think that, and I don't know all that much about how much memory an iPhone has to work with or how much creating a single IBOutlet drains your resources, but I do have quite a few IBOutlets in that View Controllereric.mitchell
No that way of presenting views isn't eating up memory. Instead of a for statement try just doing one animation at a time and see if the choppiness still occurs.SimplyKiwi
Yeah, that stopped the choppiness, which doesn't make sense to me because even when only two squares are moving (and it isn't choppy) the others are hidden, but still moving, right?eric.mitchell
I am slightly confused, did this solve your issue? If not, if you want invisible objects to move to a specific point, don't animate it, Just do CGPointMake.SimplyKiwi

2 Answers

2
votes

There are a few things that can cause this. It always comes down to how complex the content is. Also, simulator can be really bad about handling animation, so be sure you are testing on real hardware.

Are there large images on the buttons? Are the buttons casting shadows? Those things can slow it down.

Also- use block based animation. Not the old begin-commit methods.

0
votes

Not exactly sure why it's slow, but have you tried nesting the thing differently?

if(!shouldMove)
    return;

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

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

[UIView commitAnimations];

does (almost - the logic is a bit different in the !shouldMove case, but that's a different story) the same, but in a cleaner way.