I have an animation that “lifts” up a button and drops a shadow. Here’s how I do it, for example.
button1shadow.alpha = 0;
button1shadow.hidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
CGRect frame11 =searchByName.frame;
frame11.origin.y -=20;
frame11.origin.x +=20;
searchByName.frame = frame11;
searchByNameLabel.frame = frame11;
CGRect frame21 = button1shadow.frame;
frame21.origin.y +=10;
frame21.origin.x -=10;
button1shadow.frame = frame21;
searchByName.alpha = 1;
button1shadow.alpha = 0.1;
[UIView commitAnimations];
This works just fine if I run it by itself.
Then I put this code right after the code above.
button1shadow.hidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:2.0];
[UIView setAnimationDuration:1.5];
CGRect frame11 =searchByName.frame;
frame11.origin.y +=20;
frame11.origin.x -=20;
searchByName.frame = frame11;
searchByNameLabel.frame = frame11;
CGRect frame21 = button1shadow.frame;
frame21.origin.y -=10;
frame21.origin.x +=10;
button1shadow.frame = frame21;
searchByName.alpha = 1;
button1shadow.alpha = 0.1;
[UIView commitAnimations];
Both work fine seperately, but when I combine them right after each other the first animation is not displayed, but the button jumps up to the coordinates I assigned instead of animating. Any ideas?
Edit:
I also tried to call the second animation by using:
[NSTimer timerWithTimeInterval:2.0 target:self selector:@selector(lowerButtons) userInfo:nil repeats:NO];
However, it didn’t seem to even call “lowerButtons”.
You’re setting an animation delay, so this should work, but have you tried doing the second animation in a delegate callback? Check out
UIView’s+setAnimationDelegate:and+setAnimationDidStopSelector:methods.