我有 3 张卡。首先,所有卡片都移动到右侧,然后 1 秒后,卡片 2 将出现在 View 的左侧,然后再过一段时间,第二张卡片 2 移动到右侧。我使用以下代码实现了这一点。当 View 加载时,我有以下代码,
counter = 0;
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(performAnimationToRight) userInfo:nil repeats:YES];
这里是performAnimationToRightMethod的实现
-(void)performAnimationToRight
{
if (counter == 0) {
CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(388,0);
[UIView beginAnimations:@"Move1" context:nil];
[UIView setAnimationDuration:2];
card0.transform = transformToLeft;
card1.transform = transformToLeft;
card2.transform = transformToLeft;
[UIView commitAnimations];
}else if(counter == 50){
card2.frame = CGRectMake(-300,card2.frame.origin.y, card2.frame.size.width, card2.frame.size.height);
}else if(counter == 200){
timer = nil;
counter = 0;
CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(-300,0);
[UIView beginAnimations:@"Move2" context:nil];
[UIView setAnimationDuration:2];
card2.transform = transformToLeft;
[UIView commitAnimations];
}
counter++;
}
问题是在最后一个 Action 中card2不是向右移动而是向左移动,这就是我是否使用的问题,
CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(-300,0);
或
CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(+300,0);
最佳答案
两条评论:
首先,您将 card2 移动到左侧 counter == 50
,方法是将其框架原点设置为(可能)位于起始位置的左侧。
其次,使用CAKeyframeAnimation
可以更轻松地实现。您不必管理 NSTimer
和 counter
机制。
关于ios - 分 3 步依次完成其他 ios 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9372560/