views:

32

answers:

1
-(ibaction)sometouched:(id)sender
{
    [UIView beginAnimations:@"first one" context:nil];
    [UIView setAnimationDuration:1.0];
    [myview setFrame:CGRectMake(0,y,width.height.);
    [UIView commitAnimations];

    [UIView beginAnimations:@"second one" context:nil];
    [UIView setAnimationDuration:1.0];
    [myview setFrame:CGRectMake(x,0,width.height.);
    [UIView commitAnimations];
}

This is just a demonstrate. What I want is the animation will take 2 parts. the first one moves the view down, and the second one moves it to the right. but what i've got is it quickly moves down and then moves correctly to the right.

what did i miss here?

+1  A: 

You need to start the second animation from the animationDidStop delegate method.

-(ibaction)sometouched:(id)sender
{
    [UIView beginAnimations:@"first one" context:nil];
    [UIView setAnimationDuration:1.0];
    [myview setFrame:CGRectMake(0,y,width.height.);
    [UIView setAnimationDelegate:self];
    [UIView commitAnimations];
}

- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
    [UIView beginAnimations:@"second one" context:nil];
    [UIView setAnimationDuration:1.0];
    [myview setFrame:CGRectMake(x,0,width.height.);
    [UIView setAnimationDelegate:nil];
    [UIView commitAnimations];
}
taskinoor