2013-02-05 110 views
1

我想要像ECG(心跳监视器)一样获得连续的脉冲效果。目前我正在使用两个动画块。UIViewAnimationOptionRepeat在两个动画之间暂停

[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..

任何HEP将不胜感激..

提前谢谢..

只要你知道我我也试过UIViewAnimationCurveEaseInOut ..但它仍然暂停..

+0

第一条评论:setAnimationCurve:“如果从动画块外调用此方法,则不执行任何操作。” – meronix

+0

second:commitAnimations如果没有开始就没有用beginAnimations:context:被调用 – meronix

+0

@meronix:我加了setAnimationCurve:方法只是为了试验。但是在我添加该方法之前,它并没有流畅的动画效果。 –

回答

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){}]; 

的重要的变化是我不得不更换UIViewAnimationCurveLinearUIViewAnimationOptionCurveLinear

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){}]; 

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