循环和中断动画

时间:2012-05-18 10:02:13

标签: iphone objective-c ios animation

我希望有人可以告诉我循环动画的正确方法,用另一个动画中断动画,然后恢复原始动画。我目前设置动画的方式是这样的:

-(void) firstAnimation
{
[UIView animateWithDuration:1.0f delay:0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionAllowUserInteraction) animations:^{
        CGPoint bottomPoint = CGPointMake(215.0, 380.0);
        imgBee.center = bottomPoint;
    } completion:^(BOOL finished) {

    }];
}

中断:

-(void) interruptAnimation
{

    CGPoint point1 = CGPointMake(500, 500);
    CGPoint originalCenter = CGPointMake(215.0, 410.0);
    [UIView animateWithDuration:2.0f delay:0 options:(UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAutoreverse) animations:^{
        imgBee.center = point1;
    } completion:^(BOOL finished) {
        imgBee.center = originalCenter;
        [self firstAnimation];

    }];   
}

我很确定这不是最好的解决方法。当我用interruptAnimation中断时,原始动画突然开始,当我调用[self firstAnimation]时,动画也会突然重启。

我很感激任何帮助。

1 个答案:

答案 0 :(得分:0)

看一下有关暂停和恢复动画的问答,这可能会有所帮助:QA1673