我正在尝试使用以下代码来执行一些动画
-(void) performSlidingfromX:(int) xx fromY:(int) yy
{
UIImageView *Image= [self getImage];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 1.0];
[UIView setAnimationBeginsFromCurrentState:true];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[token setFrame:CGRectMake(xx, yy, 64, 64)];
[UIView commitAnimations];
}
我在 for 循环中像这样调用
for (i = 0; i < totMoves; i++) {
Moment *m = [moments objectAtIndex:i];
int xx= [m X];
int yy= [m Y];
[self performSlidingfromX:xx fromY:yy];
}
我面临的问题是它的动画到最终位置,例如,如果我输入 xx,yy 的以下时刻
0,0
50,0
50,50
它将图像对角线从 0,0 移动到 50,50,我希望它先水平滑动,然后垂直滑动。
有帮助吗?
Thanks
使用新的块动画。它简单且稳定:
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[token setFrame:CGRectMake(xx, 0, 64, 64)];
//here you may add any othe actions, but notice, that ALL of them will do in SINGLE step. so, we setting ONLY xx coordinate to move it horizantly first.
}
completion:^(BOOL finished){
//here any actions, thet must be done AFTER 1st animation is finished. If you whant to loop animations, call your function here.
[UIView animateWithDuration:0.5
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{[token setFrame:CGRectMake(xx, yy, 64, 64)];} // adding yy coordinate to move it verticaly}
completion:nil];
}];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)