为什么这两个UIViews不会使用我的动画淡入淡出?

时间:2011-04-15 14:41:55

标签: iphone cocoa-touch ios ipad

我有两种观点,我想淡入淡出。我尝试了下面的代码,但它似乎不起作用,转换只发生一次。谁能告诉我正确的方法来完成我想做的事情?

vView1.alpha = 0.0;
vView2.alpha = 1.0;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.55];
[UIView setAnimationRepeatCount:0];
vView1.alpha = (vView1 == 0.0) ? 1.0 : 0.0;
vView2.alpha = (vView2 == 0.0) ? 1.0 : 0.0;
[UIView commitAnimations];

我在viewWillAppear中进行了设置,以防万一。

来自Apple Doc:

animationRepeatCount
Specifies the number of times to repeat the animation.

@property(nonatomic) NSInteger animationRepeatCount
Discussion
The default value is 0, which specifies to repeat the animation indefinitely.

Availability
Available in iOS 2.0 and later.
Declared In
UIImageView.h

3 个答案:

答案 0 :(得分:1)

UIImageView类也有animationRepeatCount属性,设置为0表示“无限重复”。设置为0时UIView类的属性表示“重复一次。”

您正在使用UIView动画。

如果你想无限期地重复这个动画,你可以尝试设置一个选择器,以便在动画完成后使用setAnimationDidStopSelector:来执行,它只是调用你的函数来做动画。请务必使用值setAnimationDelegate:调用self,以便实际调用您的选择器。

答案 1 :(得分:0)

来自Apple文档:

  

repeatCount   动画重复的次数。该值可以是分数。如果指定值0,则动画执行一次而不重复。

这就是你只看一次动画的原因。

答案 2 :(得分:0)

据我了解您的问题,您希望vView1出现然后再次消失。然后将repeatCount设置为1应该可以工作。并省略if语句,如下所示:

vView1.alpha = 0.0;
vView2.alpha = 1.0;

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.55];
[UIView setAnimationRepeatCount:1];
vView1.alpha = 1.0;
vView2.alpha = 0.0;
[UIView commitAnimations];
相关问题