ios - 分 3 步依次完成其他 ios 的动画

标签 ios animation

我有 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 可以更轻松地实现。您不必管理 NSTimercounter 机制。

关于ios - 分 3 步依次完成其他 ios 的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9372560/

相关文章:

css - Div css 过渡不会在切换时折叠

javascript - 如何制作像Apple.com那样的图片动画效果?

javascript - CSS 动画 - 在标题旁边从左到右滑动线条

ios - 在 iOS 中加载多个图像时,使用 send_data 加载的图像半损坏

ios - 排序快速插入的 Realm 记录

objective-c - 如何在启用 ARC 的情况下正确使用 CFURLCreateCopyAppendingPathComponent?

javascript - jQuery 事件传播?

jquery - iPhone/iPad 上的点击监听器

ios - 在大头针位置居中 map

弹丸给出直线的Python动画