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 显示的是哪个动画图像?
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01