UIViewAnimationOptionRepeat在两个动画之间暂停

时间:2013-02-05 10:35:09

标签: iphone ios animation

我想像ECG(心跳监测器)一样实现连续脉冲效果。目前我正在使用两个动画块。

[UIView animateWithDuration: 2.0f delay: 0.0f options: UIViewAnimationOptionRepeat  | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionTransitionNone | UIViewAnimationOptionOverrideInheritedDuration
                 animations:^{ [image1 setFrame:CGRectMake(0,200,320,70)];}
                 completion:^(BOOL finished){[image1 setFrame:CGRectMake(-320,200,320,70)];}];

[UIView animateWithDuration:2.0f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionTransitionNone | UIViewAnimationOptionOverrideInheritedDuration
                 animations:^{ [image2 setFrame:CGRectMake(320,200,320,70)];}
                 completion:^(BOOL finished){[image2 setFrame:CGRectMake(0,200,320,70)];}];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];

[UIView commitAnimations];

此动画在完成后会重复播放,但在再次凝视之前需要暂停一下..我想删除其间的暂停并实现连续流畅的动画..

In case I'm not clear to you, i want to achieve this kind of effect..

任何肝脏都会非常感激..

提前致谢..

就这样你知道我也尝试了UIViewAnimationCurveEaseInOut ..但它仍然暂停..

2 个答案:

答案 0 :(得分:4)

最后我发现...我使用下面的代码来实现平滑和非暂停的动画。

[UIView animateWithDuration:2.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveLinear
                 animations:^{ [image1 setFrame:CGRectMake(0,200,320,70)];}
                 completion:^(BOOL finished){}];

[UIView animateWithDuration:2.5f delay:0.0f options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionCurveLinear
                 animations:^{ [image2 setFrame:CGRectMake(320,200,320,70)];}
                 completion:^(BOOL finished){}];

重要的变化是我必须用 UIViewAnimationOptionCurveLinear 替换 UIViewAnimationCurveLinear

答案 1 :(得分:1)

这对我有用,没有停顿。

你正在改变位置,没有大小,所以可能更好地改变中心而不是框架

float originalX = image1.center.x;
[UIView animateWithDuration: 2.0f delay: 0.0f options: UIViewAnimationCurveLinear | UIViewAnimationOptionRepeat  | UIViewAnimationOptionAllowUserInteraction                         
          animations:^{ image1.center = CGPointMake(originalX + 320, image1.center.y);}
                         completion:^(BOOL finished){}];

你真的不需要在完成块中设置原始位置,“重复”选项为你做了