iPhone-知道UIImageView何时加载其图像 [英] iPhone - Knowing when an UIImageView has loaded its image

查看:43
本文介绍了iPhone-知道UIImageView何时加载其图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将5MP图像加载到UIImageView中,并调用 self.imagecontainer.image = myUIImage .myUIImage是来自iPhone相机的图像.

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.

我怎么知道图像已加载并显示,而不仅仅是UIImageView正在处理?

How may I know that the image is loaded and displayed, and not just still being processed by the UIImageView ?

推荐答案

嗯...首先,您不应该在imageView中设置5MP图像.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.

因此,您应该将图像调整为满足屏幕显示需求的最小尺寸,然后在imageView中设置该图像.这是我最喜欢的有关如何调整图像大小的博客文章:

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.

现在,您的问题.您无法确定何时显示图像,但缩放后图像会如此迅速地发生,您只能假设设置后立即显示图像.在后台线程上进行缩放也是如此.缩放完成后,向主线程发送一条消息,以在imageView中设置缩放后的图像,然后执行所需的任何操作.

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.

这篇关于iPhone-知道UIImageView何时加载其图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆