Multiple animations at the same time?

Discussion in 'iOS Programming' started by BlackWolf, Apr 22, 2009.

  1. BlackWolf macrumors regular

    Apr 9, 2009
    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?


    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.
  2. sanniv macrumors newbie

    Apr 22, 2009
    Hello BlackWolf,

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

  3. BlackWolf thread starter macrumors regular

    Apr 9, 2009
    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

Share This Page