1

我想实现像 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];

此动画在完成后重复,但在再次凝视之前需要稍作停顿。我想消除中间的停顿并实现连续流畅的动画。

如果我不清楚你,我想达到这种效果..

任何 hep 将不胜感激..

提前致谢..

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

4

2 回答 2

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

于 2013-02-06T05:47:57.703 回答
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){}];

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

于 2013-02-05T11:04:54.100 回答