Code for IOS development: jiugongge and jiugong for ios development

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.