开发者

Assigning an animation to a UIButton

开发者 https://www.devze.com 2023-01-30 08:29 出处:网络
If I have an animation which can play with an array of images. How Do I set this to play on a button? I want the buttons image to display the animation?

If I have an animation which can play with an array of images.

How Do I set this to play on a button? I want the buttons image to display the animation?

Thank开发者_Go百科s


If you need an actual button, then the choice is clear: You will need to build your own custom UIControl object to achieve this. Quite possibly you can just subclass UIButton, and handle animating the images that way. I do something similar in one of my apps using core animation to fade between a series of 6 images. It works quite well.

I will point you at the UIControl class reference. Please read the intro material on the page, it links to other pages, like event handling. As well, I will also point you at the CABasicAnimation class reference, with the same caveat applied.

Remember, a UIControl is just a UIView, except that it handles events a particular way.


Simplest way is just to place a custom UIButton (ie invisible to the user) above your UIImageView. Then it will appear that the button is animated but in reality it will be the images underneath the button that are animated.


Create an array, eg. myArray with the filenames of your images. assign this array to a UIImage with myImage.animationImages = myArray; then use setImage:forState to assign this animation to the button.

0

精彩评论

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

关注公众号