iPhone - Knowing when an UIImageView has loaded it

2019-08-16 08:36发布

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 ?

1条回答
Evening l夕情丶
2楼-- · 2019-08-16 09:14

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.

查看更多
登录 后发表回答