Determine which of its animationImages a UIImageView is displaying?(确定 UIImageView 显示的是哪个动画图像?)
问题描述
有没有办法找出 UIImage 在其动画的哪一帧上?当你启动它时,你给它一个动画图像数组,所以它显然必须将当前图像的索引存储在某个地方.你知道我怎么能找到这个吗?另外,有没有办法告诉 UIImageView 从哪一帧开始动画?
Is there a way to find out which frame of its animation a UIImage is on? When you start it you give it an array of animationImages, so it clearly has to be storing the index of the current image somewhere. Do you know how I can find this out? Also, is there a way to tell a UIImageView which frame to start its animation on?
推荐答案
在类转储 UIKit 后,我既找不到文档中的属性,也找不到可疑的 ivar 或私有方法,所以我能想到的最好的方法是:
I couldn't find neither a property in the documentation, nor a suspicious ivar or private method after class-dumping UIKit, so the best I could think of is:
NSDate *startDate; // instance variable
- (void)startAnimation
{
startDate = [NSDate date];
[imageView startAnimating];
}
- (int)currentImageIndex
{
NSTimeInterval elapsed = -1 * [startDate timeIntervalSinceNow];
int nFrames = imageView.animationImages.count;
NSTimeInterval frameDuration = imageView.animationDuration / nFrames;
int current = elapsed / frameDuration;
return current % nFrames;
}
关于如何在特定图像上开始动画:使用 NSMutableArray
存储图像,并旋转数组,使其第一个元素是您要开始的图像,然后重新- 设置图像视图的 animationImages
属性.要旋转 NSMutableArray
,请参阅 这个问题.
As to how to start the animation at a particular image: use an NSMutableArray
for storing the images, and rotate the array so that its first element is the image you want to begin with, then re-set the animationImages
property of the image view. To rotate an NSMutableArray
, see the answers to this question.
这篇关于确定 UIImageView 显示的是哪个动画图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:确定 UIImageView 显示的是哪个动画图像?
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01