Animating UIButton alpha with a PNG background: why does the animation get bright white as it transitions from alpha = 0 to alpha = 1?
This is something that is stumping me; I have a simple UIButton
with the following PNG as it's background:
I'm using an iOS 4 block animation, and all I'm doing is animating it's alpha
property from 0.0 to 1.0. However, while the animation is in progress, the UIButton
gets bright white, before finally settling to look like the above image when the property reaches 1.0.
开发者_StackOverflow中文版I'm pretty stumped - if, for example, I open that image in Paint.NET and slide the image's opacity from 0 to 255, I see a nice fade-in effect - which is exactly what I'm going for. But when I animate an opacity change in iOS, the button gets bright white during the middle part of the animation.
If I change the animation's duration to something extended, like 5 seconds, the effect is even more prominent. Any ideas?
Edit: I am using Xcode 4.1, and running iOS 4.3.3 (first gen iPad).
It turns out, after much consideration, that the issue was my UIButton
was a Round Rect button; the type needed to be changed to Custom. Even though the background images I set for my button worked when the type was Round Rect, applying an alpha animation to the button still caused the default white Round Rect style to appear for the duration of the animation. That is what my eyes interpreted as "bright white" during the animation - it had nothing to do with my PNG background, and everything to do with the underlying type of the button I was using.
Problem solved. Moral of the story? Change your UIButton
type to Custom if you're going to animate the button while using your own background images.
精彩评论