我有3张牌。首先所有卡片向右移动,然后1秒后,card2将出现在视图的左侧,然后在更多的第二张卡片向右移动后。我使用以下代码实现了这一点。当视图加载时,我有以下代码,
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++;
}
问题在于,在最后一个动作卡2而不是向右移动向左移动,而这是我使用的更好或更少,
CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(-300,0);
或
CGAffineTransform transformToLeft = CGAffineTransformMakeTranslation(+300,0);
答案 0 :(得分:1)
两条评论:
首先,您将卡片2的左侧移动到counter == 50
左侧,将其原点设置为(可能)在您的起始位置左侧。
其次,使用CAKeyframeAnimation
更容易实现。您无需管理NSTimer
和counter
机制。