UIViewAnimationOptionRepeat的动画不重复

时间:2015-02-27 01:47:23

标签: ios cocoa-touch uiview uiviewanimation

[UIView animateWithDuration:speedOfCutout
                      delay:0.2f
                    options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionRepeat //| UIViewAnimationOptionAutoreverse
                 animations:^{

                     CABasicAnimation *animation = [CABasicAnimation animation];
                     animation.keyPath = @"position.y";
                     animation.fromValue = @77;
                     animation.toValue = @600;
                     animation.duration = speedOfCutout;

                     [cutout.layer addAnimation:animation forKey: @"basic"];
                     cutout.layer.position = CGPointMake(160, 61);
                     [cutout.layer addAnimation:animation forKey: @"basic"];
                     cutout.layer.position = CGPointMake(160, 61);

                     [cutout.layer addAnimation:animation forKey: @"basic"];
                     cutout.layer.position = CGPointMake(160, 61);

                 }
                 completion:^(BOOL fin) {
                 }];

if (CGRectIntersectsRect(cutout.frame, shape.frame)) {
    cutout.hidden = YES;
    shape.hidden = YES;

    [cutoutMovementTimer invalidate];

    [self gameOver];

}

我有这个代码应该循环动画,直到它运行到另一个形状。但是,它只运行一次,并且在后续文章中没有做任何事情。

2 个答案:

答案 0 :(得分:0)

您正在使用CoreAnimation对象,不受UIView Animation块的影响,删除UIView Animation块并添加:

animation.autoreverses = YES;
animation.repeatCount = HUGE_VAL;

它会工作。

答案 1 :(得分:0)

试试这个: 设置animation.repeatCount = -1; 并且完成块处理形状更改事件并停止动画。