链接UIView动画?

时间:2014-08-20 05:22:33

标签: ios objective-c uiview

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

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

    -(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];
    }

1 个答案:

答案 0 :(得分:2)

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

-(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];
}