Ios 带有UIViewAnimationOptionRepeat的动画不重复
我有一段代码,应该循环动画,直到它运行到另一个形状。但是,它只运行一次,不执行任何后续操作。您正在使用CoreAnimation对象,将不受UIView动画块的影响,请删除UIView动画块并添加:Ios 带有UIViewAnimationOptionRepeat的动画不重复,ios,cocoa-touch,uiview,uiviewanimation,Ios,Cocoa Touch,Uiview,Uiviewanimation,我有一段代码,应该循环动画,直到它运行到另一个形状。但是,它只运行一次,不执行任何后续操作。您正在使用CoreAnimation对象,将不受UIView动画块的影响,请删除UIView动画块并添加: [UIView animateWithDuration:speedOfCutout delay:0.2f options:UIViewAnimationCurveEaseInOut | 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];
}
会有用的。试试这个:
设置animation.repeatCount=-1;
完成块是否处理形状更改事件并停止动画。可能是因为第一个选项不是选项,所以忽略了所有选项,所以它不起作用。我想应该是UIViewAnimationOptionCurveEaseInOut
animation.autoreverses = YES;
animation.repeatCount = HUGE_VAL;