开发者

how to execute multiple animations in a row?

-(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];
 开发者_JS百科   [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?


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜