UIImageView 是否有一个属性来指示 setImage 已完成并且动画已准备好?
刚刚开始使用 Obj-C 和 iOS 编程。我有一些代码将 imageView 加载到(隐藏:是)UIView 中 -
[bgImageView setImage:[UIImage imageNamed:@"Filename.jpg"];
然后代码在 fgImageView 和 bgImageView 上设置并提交动画。 由于某些图像可能很大,因此有时新 bgImage 中的动画不会使用其中的新背景图像进行渲染,而是“停止并显示”。请注意,在 setImage 期间不会发生停顿。它发生在代码中的第二个animationCommit期间。因为animationCommit强制应用程序等待,直到这个ImageView的动画完成。
我正在寻找的是 UIImageView 上的“setImage commit”,
我宁愿显示一个微调器,直到加载图像,然后继续播放动画,但是 UIImageView 似乎没有 isLoaded 属性班级。
有没有一种简单的方法可以确定 UIImageView 是否已通过 setImage 调用完成?
Just getting started with Obj-C and iOS programming. I have some code that loads and imageView into a (HIDDEN: YES) UIView - simply
[bgImageView setImage:[UIImage imageNamed:@"Filename.jpg"];
The code then sets and commits animations on the fgImageView and the bgImageView.
Because some of the images can be large, occasionally the animation from the new bgImage does not render with the new background image in it and instead 'stalls and displays'. Note that the stall does not happen during setImage. It happens during the second animationCommit later in code. Because animationCommit forces the application to wait until the animation of this ImageView is done.
What I'm looking for is sort of a 'setImage commit' on UIImageView,
I'd much rather display a spinner until the image is loaded, then proceed with the animation, however there doesn't appear to be an isLoaded property for UIImageView class.
Is there a simple way to determine that the UIImageView is done with the setImage call?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的直觉是 setImage 是同步处理的,特别是因为您正在谈论应用程序如何停止。您需要在 NSOperation 中运行 setImage 以允许在后台发生这种情况。
http://developer.apple.com/ library/ios/#documentation/cocoa/reference/NSOperation_class/Reference/Reference.html
然后,您将处理 KVO 操作并在那里删除微调器。
My gut is that setImage is handled synchronously, especially since you're talking about how the app stalls. You'd want to run setImage in an NSOperation to allow that happen in the background.
http://developer.apple.com/library/ios/#documentation/cocoa/reference/NSOperation_class/Reference/Reference.html
You'd then handle the KVO operation and handle removing the spinner there.
[UIImageView setImage:]
不是异步的:它是在消息返回之前立即完成的。如果视图没有立即显示图像,可能是因为一些惰性 UIImage 代码。我的猜测是[UIImage imageNamed:]
只是引用包中的文件并仅在请求图像数据后加载它。您可以尝试通过向图像发送 CGImage 消息来强制加载图像:
如果这仍然没有触发图像加载,您必须将其绘制在某处:
[UIImageView setImage:]
is not asynchronous: It's done immediately before the message returns. If the view does not show the image instantly it's probably because of some lazy UIImage code. My guess is that[UIImage imageNamed:]
just references the file in the bundle and loads it only after the image data is requested.You could try to force the image to load by sending it a CGImage message:
If this still does not trigger the image to be loaded you have to draw it somewhere:
UIImageView
- (BOOL)isAnimating
中有一个方法,因此您可能会使用:这样就足够了,还是正在进行中的其他动画会给出错误响应?
There is a method in UIImageView
- (BOOL)isAnimating
, so you could potentially use:Would that suffice or is there other animation in progress that would give false responses?