Code for IOS development: jiugongge and jiugong for ios development
When you use UIScrollView to display images, If you directly add UIImageView to UIScrollView, there is no problem when the number of images is small, but when we add a large number of images, it will occupy a large amount of memory. Let's talk about how to avoid this by re-constructing a UIScrollView that can reuse the view!
Step 1: create a custom UIScrollView
1. Add two protocols to obtain the corresponding data through the proxy, and determine the margin type through one Enumeration type
2. Implement the following code:
3. During implementation, we can use the layoutsubviews (called when UIScrollView slides) method to determine which ones should be displayed and which ones should not be displayed, if it should be displayed, we will add it to UIScrollView through the addSubview method. If it should not be displayed and already exists, we will remove it from UIScrollView and put it in a cache pool.
4. When using it, use an NSString * to determine the type of view that needs to be reused, and then obtain it from the cache pool.
5. Finally, run the program. The effect is as follows: no matter how sliding, the memory usage will be much smaller than before.
Author: Jerry Education
Source: http://www.cnblogs.com/jerehedu/
Copyright Disclaimer: The copyright of this article is shared by Yantai jereh Education Technology Co., Ltd. and the blog Park. You are welcome to repost it. However, you must keep this statement without the consent of the author and provide the original article connection clearly on the article page, otherwise, you are entitled to pursue legal liability.
Technical Consultation: