我有两个 View 想要淡入和淡出。我尝试了下面的代码,但它似乎不起作用,转换只发生一次。谁能告诉我完成我想做的事情的正确方法?
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 中进行了设置,以防万一。
来自苹果文档:
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
最佳答案
UIImageView
类还有一个 animationRepeatCount
属性,当设置为 0 时表示“无限期重复”。 UIView
类的属性设置为 0 时表示“重复一次”。
您正在使用 UIView 动画。
如果您想无限期地重复此动画,您可以尝试使用 setAnimationDidStopSelector:
设置一个选择器,以便在动画完成时执行,该选择器仅调用您的函数来执行动画。请记住还要使用 self
值调用 setAnimationDelegate:
,以便实际调用您的选择器。
关于iphone - 为什么这两个 UIView 不会使用我的动画淡入和淡出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5678408/