iPhone - 知道 UIImageView 何时加载其图像
我正在调用 self.imagecontainer.image = myUIImage
将 5MP 图像加载到 UIImageView 中。 myUIImage 是来自 iPhone 相机的图像。
这需要一些时间才能在屏幕上看到图像,即使我可以减少这个时间,当图像真正显示在屏幕上时我需要启动一个进程。
我如何知道图像已加载并显示,而不仅仅是仍在由 UIImageView 处理?
I'm loading a 5MP image into an UIImageView calling self.imagecontainer.image = myUIImage
. myUIImage is an image coming from the camera of the iPhone.
This takes some time before the image can be seen on screen, and even if I can reduce this time, I need to start a process when the image is really displayed on the screen.
How may I know that the image is loaded and displayed, and not just still being processed by the UIImageView ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯...第一件事是你不应该在 imageView 中设置 5MP 图像。 imageView 仅用于屏幕显示,即使它缩放您为显示目的而设置的图像,原始图像也会被保留,因此您的内存占用量会大大增加。如果您这样做最多,您将得到一个性能较差的应用程序,该应用程序会处理大量内存警告。最坏的情况是,你会经常崩溃。
因此,您应该将图像大小调整为满足屏幕显示需求的最小尺寸,然后在 imageView 中设置该图像。这是我最喜欢的关于如何调整图像大小的博客文章: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way。
现在,回答你的问题。您无法确定图像何时显示,但是一旦缩放,它就会发生得如此之快,您可以假设它在您设置后立即显示。所以在后台线程上进行缩放。当缩放完成后,向主线程发送消息以在 imageView 中设置缩放后的图像,然后执行您想要的操作。
Well... first thing is you shouldn't be setting a 5MP image in an imageView. An imageView is meant for on screen display only and even though it scales the image you set for display purposes the original is retained so your memory footprint goes way up. If you do this at best you will have a poor performing app that deals with lots of memory warnings. At worst, you'll crash often.
So, you should resize your image to the smallest size that meets your onscreen display needs and then set that image within your imageView. This is my favorite blog post on how to resize images: http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way.
Now, to your question. You can't know for sure when the image is displayed but it will happen so quickly once you scaled you can just assume it is displayed as soon as you set it. So do your scaling on a background thread. When the scaling is done, send a message to the main thread to set the scaled image in the imageView and then do whatever you want.