开发者

Why won't these two UIViews fade in and out using my animation?

I have two views that I would like to fade in and out. I tried the code below, but it does not seem to work, the transition only happens once. Can anyone tell me the right way to accomplish what I am trying to do?

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开发者_StackOverflow == 0.0) ? 1.0 : 0.0;
[UIView commitAnimations];

I set this up in viewWillAppear, in case that matters.

From the 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


The UIImageView class also has an animationRepeatCount attribute, when set to 0 means "repeat indefinitely". The UIView class's attribute when set to 0 means "repeat once."

You're using UIView animation.

If you want to repeat this animation indefinitely, you might try setting a selector to execute when the animation finishes using setAnimationDidStopSelector: that simply calls your function to do the animation. Remember to also call setAnimationDelegate: with a value of self so that your selector actually gets invoked.


From the Apple documentation :

repeatCount The number of times animations repeat. This value can be a fraction. If you specify the value 0, the animation is performed once without repeating.

That's why you see your animation only once.


As I understand your question, you want vView1 to appear and then disappear again. Then setting repeatCount to 1 should work. And leave out the if statement, something like this:

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜