链接 UIView 动画? [英] Chaining UIView animations?

查看:34
本文介绍了链接 UIView 动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让图像从坐标 x=80 和 y=249 开始,这将移动到 x=284 和 y=99.然后从那里它会转到 x=488 和 y=249.

I am trying to make an image start at coordinates x=80 and y=249 which would move to x=284 and y=99. Then from there it would go to x=488 and y=249.

这就是我得到的,但由于某种原因,图像从 x=284 和 y=99 开始,然后移动到 x=488 和 y=249.我需要帮助来解决这个问题.

This is what i got, but for some reason the image starts at x=284 and y=99 and moves to x=488 and y=249. I need help to fix this issue.

    -(void)BallArchR{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration: 1.5];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        CGPoint center = [Ball center];
        center.x = 284;
        center.y = 99;
        [Ball setCenter:center];
        [UIView commitAnimations];
        [self BallArchR2];
    }

    -(void)BallArchR2{
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration: 1.5];
        [UIView setAnimationCurve:UIViewAnimationCurveLinear];
        CGPoint center = [Ball center];
        center.x = 488;
        center.y = 249;
        [Ball setCenter:center];
        [UIView commitAnimations];
    }

推荐答案

因为你直接从 BallArchR 方法调用 BallArchR2 方法.但实际上,BallArchR方法的动画并不完整,在调用BallArchR2方法之前.所以,在第一个 BallArchR 方法动画完成后调用 BallArchR2 方法.所以你可以试试这个希望它对你有帮助:

because of you call BallArchR2 method from BallArchR method directly. But in actual, the animation of BallArchR method is not complete and before that BallArchR2 method is called. So, call BallArchR2 method after the completion of first BallArchR method animation. So you can Try this hope it helps you:

-(void)BallArchR{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 1.5];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    CGPoint center = [Ball center];
    center.x = 284;
    center.y = 99;
    [Ball setCenter:center];
    [UIView commitAnimations];

    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 1.55 * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self BallArchR2];
    });
}

-(void)BallArchR2{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration: 1.5];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    CGPoint center = [Ball center];
    center.x = 488;
    center.y = 249;
    [Ball setCenter:center];
    [UIView commitAnimations];
}

这篇关于链接 UIView 动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆