PDA

View Full Version : Multiple animations at the same time?




BlackWolf
Apr 22, 2009, 11:06 AM
Hi,
I am currently working on an app where it can happen that multiple animations of the same object are started simultanously.
to be more specific, the position of the object (an UIView) is changed. while that animation is in progress, a "flip" (setAnimationTransition:forView:cache:) animation or other adjustments to the objects position can occur.

After I read through the API reference regarding this I thought those animations should be be queued and fired when the current animation is done. This from commitAnimations:

Animations are run in a separate thread so the application is not blocked. In this way, multiple animations can be piled on top of one another.


To simplify things, I wrote a really basic app that only creates a view and executes two move-animations. even this simple app doesn't behave like I want it to: finish one animation, then perform the other. here's the code:

- (void)viewDidLoad {
UIView *wrapper = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)];
wrapper.backgroundColor = [UIColor redColor];
[self.view addSubview:wrapper];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5];
wrapper.frame = CGRectMake(290,430,30,30);
[UIView commitAnimations];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationDuration:5];
wrapper.frame = CGRectMake(0,430,30,30);
[UIView commitAnimations];

[super viewDidLoad];
}

what happens is that the first animation is simply ignored. the view starts at 290,430 and then moves to 0,430.

ideas? did I get something wrong? how do you handle multiple animations properly?

thanks!

PS: setAnimationBeginsFromCurrentState: doesn't work at all for me. I don't want it, but just for testing purposes I tried it but it doesn't change anything.
PPS: funny thing: if I replace the second animation with a flip-animation, the flip-animation is skipped and the first move-animation is executed.



sanniv
Apr 23, 2009, 07:36 AM
Hello BlackWolf,

You need to use timers to make some delay between two animation.






Hi,
I am currently working on an app where it can happen that multiple animations of the same object are started simultanously.
to be more specific, the position of the object (an UIView) is changed. while that animation is in progress, a "flip" (setAnimationTransition:forView:cache:) animation or other adjustments to the objects position can occur.

After I read through the API reference regarding this I thought those animations should be be queued and fired when the current animation is done. This from commitAnimations:


To simplify things, I wrote a really basic app that only creates a view and executes two move-animations. even this simple app doesn't behave like I want it to: finish one animation, then perform the other. here's the code:

- (void)viewDidLoad {
UIView *wrapper = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)];
wrapper.backgroundColor = [UIColor redColor];
[self.view addSubview:wrapper];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5];
wrapper.frame = CGRectMake(290,430,30,30);
[UIView commitAnimations];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationDuration:5];
wrapper.frame = CGRectMake(0,430,30,30);
[UIView commitAnimations];

[super viewDidLoad];
}

what happens is that the first animation is simply ignored. the view starts at 290,430 and then moves to 0,430.

ideas? did I get something wrong? how do you handle multiple animations properly?

thanks!

PS: setAnimationBeginsFromCurrentState: doesn't work at all for me. I don't want it, but just for testing purposes I tried it but it doesn't change anything.
PPS: funny thing: if I replace the second animation with a flip-animation, the flip-animation is skipped and the first move-animation is executed.

BlackWolf
Apr 23, 2009, 08:23 AM
Hello BlackWolf,

You need to use timers to make some delay between two animation.

thanks for the answer, that's what I thought. it's not THAT easy because the animations are fired when the user double-taps, but I'll get it to work somehow :D