将动画分配给UIButton [英] Assigning an animation to a UIButton
问题描述
如果我有一个可以播放一系列图像的动画.
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?
谢谢
推荐答案
如果您需要一个实际的按钮,那么选择很明确:您将需要构建自己的自定义 UIControl
对象以实现此目的.您很可能可以仅继承UIButton,并以这种方式处理动画图像.我在一个应用程序中使用核心动画在一系列6张图像之间淡入淡出,做了类似的事情.效果很好.
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.
我将指向您 UIControl类参考.请阅读该页面上的介绍材料,该材料链接到其他页面,例如事件处理.同样,我还将指向您CABasicAnimation类引用,并应用了相同的警告.
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.
请记住,UIControl只是UIView,只是它以特定方式处理事件.
Remember, a UIControl is just a UIView, except that it handles events a particular way.
这篇关于将动画分配给UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!