Animated Images in a UIButton(UIButton 中的动画图像)
问题描述
为按钮图像设置动画的最佳方式是什么?
What is the best way to animate images of a button?
假设我想循环 6 帧,让用户仍然可以点击按钮?
Say I want to cycle through like 6 frames and have the user still be able to click the button?
我是否应该为图像设置动画并在界面构建器中只在其顶部添加一个不可见的按钮?
Should I animate the images and just have an invisible button on top of it in interface builder?
有没有办法在定义 UIButton
时为它们设置动画?
Is there a way to animate them within defining the UIButton
?
或者更好地为图像制作动画并找到用户的接触点并采取行动?
Or is it better to animate images and find the users touch point and act on that?
推荐答案
您可以使用 UIButton
的 imageView 属性来做到这一点.这将允许按钮的行为与您的图像动画一样正常.这是一个例子:
You can do this using the imageView property of UIButton
. This will allow the button to behave as it normally would with your images animating on it. Here's an example:
NSMutableArray *imageArray = [NSMutableArray new];
for (int i = 1; i < 4; i ++) {
[imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i]]];
}
[myButton setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
[myButton.imageView setAnimationImages:[imageArray copy]];
[myButton.imageView setAnimationDuration:0.5];
[myButton.imageView startAnimating];
这篇关于UIButton 中的动画图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIButton 中的动画图像


基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01