About Uicollectionview's personal learning

Source: Internet
Author: User

It is well known that in the development process, when there is a business need similar to waterfall flow, the use of UITableView can achieve similar results, but Apple developed Uicollectionview seems to greatly facilitate the workload of developers, making this effect more efficient. As long as we are using the rewrite Uicollectionview uicollectionviewlayout can be achieved.

Working principle: To realize the waterfall flow effect of several important methods to parse.

1,-(void) Preparelayout The method is called after the layout is ready. All properties are determined at this time CollectionView. The reader can use CollectionView as a canvas, and with a canvas, we can draw each item on top of it.

2,-(cgsize) collectionviewcontentsize//Set the display range of CollectionView

3,-(Nsarray *) Layoutattributesforelementsinrect: (cgrect) Rect//Returns the properties of all views in CollectionView view ( Uicollectionviewlayoutattributes) array

4,-(Uicollectionviewlayoutattributes *) Layoutattributesforitematindexpath: (Nsindexpath *) IndexPath Returns the property of each item for the Indexpath, which can contain frame, set height, width.

5,-(BOOL) Shouldinvalidatelayoutforboundschange: (CGRect) Newbounds called when the position of the CollectionView view has changed. Yes indicates a re-layout, no means no re-layout.
The most important of these methods is the 3,4 method, which returns an array of all the view attributes in the 3 method, lays out the properties according to these attributes, and the 4 method returns the property of each item, where we set the property of each item (mainly frame), You can let collectionview the layout according to our wishes! (Here we do not need to use the 1 method, if the item property depends on the sliding changes, at this point need to change the layout at any time)

About Uicollectionview's personal learning

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.