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 中的动画图像
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- URL编码Swift iOS 2022-01-01
- UITextView 内容插图 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01