0

我在平移对象后设置动画效果

-(void)panView:(UIPanGestureRecognizer*)recognizer{
    //do sth...

    if(recogizer.state==UIGestureRecognizerStateEnded){
        [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut animation^{
            //do sth2...
        }completion:^(BOOL finished){
            //do sth3...
        }];
    }

}

问题是在播放动画时,我再次平移该对象。新的平移不会发生,我应该等到动画完成才能再次平移。

我怎样才能中断动画突然做新的平移???

解决方案

将 UIViewAnimationOptionAllowUserInteraction 添加到选项。并且可以在重做平移之前设置 self.layer removeAllAnimations。

4

1 回答 1

0

试试下面的代码

-(void)panView:(UIPanGestureRecognizer*)recognizer
{

    //do sth...

    [animatingView.layer removeAllAnimations];

    if(recogizer.state==UIGestureRecognizerStateEnded)
    {
        [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseOut | UIViewAnimationOptionAllowUserInteraction animation^{

            //do sth2...

        }completion:^(BOOL finished){

            //do sth3...

        }];
    }

}
于 2013-05-01T08:45:46.793 回答