iOS Development Uicollectionview Properties Introduction

Source: Internet
Author: User


The initial recognition of CollectionView through a layout strategy
-(Instancetype) initWithFrame: (CGRect) frame collectionviewlayout: (uicollectionviewlayout *) layout;

Gets and sets the layout of the collection
@property (nonatomic, strong) Uicollectionviewlayout *collectionviewlayout;

Data sources and agents
@property (nonatomic, weak, nullable) ID <UICollectionViewDelegate> delegate;
@property (nonatomic, weak, nullable) ID <UICollectionViewDataSource> dataSource;

Register a cell (item) from a class or Xib file
-(void) RegisterClass: (Nullable Class) Cellclass forcellwithreuseidentifier: (NSString *) identifier;
-(void) registernib: (Nullable uinib *) nib Forcellwithreuseidentifier: (NSString *) identifier;


-(void) CollectionView: (Uicollectionview *) CollectionView Didhighlightitematindexpath: (Nsindexpath *) indexPath// One click Item execution
{
NSLog (@ "-----------1------1----");
}
-(void) CollectionView: (Uicollectionview *) CollectionView Didunhighlightitematindexpath: (Nsindexpath *) indexPath// Click to release the hand after the execution
{
NSLog (@ "-----------2------2----");
}
The following two methods are similar to the above, where a header or tail view class is registered
The second parameter is the SET header view or the tail view system, which defines the two strings for us.
Uikit_extern nsstring *const uicollectionelementkindsectionheader Ns_available_ios (6_0);
Uikit_extern nsstring *const uicollectionelementkindsectionfooter Ns_available_ios (6_0);
-(void) RegisterClass: (Nullable Class) Viewclass forsupplementaryviewofkind: (NSString *) elementkind Withreuseidentifier: (NSString *) identifier;
-(void) registernib: (Nullable uinib *) nib Forsupplementaryviewofkind: (NSString *) kind withreuseidentifier: (NSString * ) identifier;

The two methods are to remove the cell or the End-to-end view from the reuse pool
-(__kindof Uicollectionviewcell *) Dequeuereusablecellwithreuseidentifier: (NSString *) identifier Forindexpath: ( Nsindexpath *) Indexpath;
-(__kindof Uicollectionreusableview *) Dequeuereusablesupplementaryviewofkind: (NSString *) elementKind Withreuseidentifier: (NSString *) identifier Forindexpath: (Nsindexpath *) Indexpath;

Sets whether the default yes is allowed to be selected
@property (nonatomic) BOOL allowsselection;

Sets whether to allow multiple selection of default No
@property (nonatomic) BOOL allowsmultipleselection;

Get location information for all selected item
-(Nullable Nsarray<nsindexpath *> *) Indexpathsforselecteditems;

Set to select an item and slide the view to the appropriate position, Scrollposition is the relative parameter of the slide position, as follows:
/*
typedef ns_options (Nsuinteger, uicollectionviewscrollposition) {
No
Uicollectionviewscrollpositionnone = 0,
Vertical layout is used in the corresponding upper and lower
Uicollectionviewscrollpositiontop = 1 << 0,
uicollectionviewscrollpositioncenteredvertically = 1 << 1,
Uicollectionviewscrollpositionbottom = 1 << 2,
Horizontal layout using the corresponding left-right
Uicollectionviewscrollpositionleft = 1 << 3,
uicollectionviewscrollpositioncenteredhorizontally = 1 << 4,
Uicollectionviewscrollpositionright = 1 << 5
};
*/
-(void) Selectitematindexpath: (Nullable Nsindexpath *) Indexpath animated: (BOOL) animated scrollposition: ( uicollectionviewscrollposition) scrollposition;

Uncheck an item
-(void) Deselectitematindexpath: (Nsindexpath *) Indexpath animated: (BOOL) animated;

Reload data
-(void) reloaddata;

The following two methods, you can reset the layout of the collection, followed by a more than a layout after the completion of the callback, iOS7 can be used
Use these two methods to produce a very cool animation effect
-(void) Setcollectionviewlayout: (Uicollectionviewlayout *) layout animated: (BOOL) animated;
-(void) Setcollectionviewlayout: (Uicollectionviewlayout *) layout animated: (BOOL) animated completion: (Void (^ __ Nullable) (BOOL finished)) Completion Ns_available_ios (7_0);

The following methods are more powerful and we can set the animation for the layout changes
This method passes in a layout policy layout, and the system starts to render the layout, returning a Uicollectionviewtransitionlayout object
This Uicollectionviewtransitionlayout object manages the associated properties of the animation, and we can set
-(Uicollectionviewtransitionlayout *) Startinteractivetransitiontocollectionviewlayout: (UICollectionViewLayout *) Layout completion: (nullable uicollectionviewlayoutinteractivetransitioncompletion) completion Ns_available_ios (7_0 );
Once the animation settings are ready, we need to call the following method to show the layout animation, and then call the block callback for the above method
-(void) finishinteractivetransition Ns_available_ios (7_0);
Calling this method cancels the layout animation setting above, and then the block callback for the above method is also used
-(void) cancelinteractivetransition Ns_available_ios (7_0);

Get the number of partitions
-(Nsinteger) numberofsections;

Gets the item number of a partition
-(Nsinteger) Numberofitemsinsection: (nsinteger) Section;

The following two methods get the layout property of the item or the Kinsoku view, which is the Uicollectionviewlayoutattributes object
Store the relevant data of the layout, can be used to do a completely custom layout, the following blog will introduce
-(Nullable Uicollectionviewlayoutattributes *) Layoutattributesforitematindexpath: (Nsindexpath *) IndexPath;
-(Nullable Uicollectionviewlayoutattributes *) Layoutattributesforsupplementaryelementofkind: (NSString *) kind Atindexpath: (Nsindexpath *) Indexpath;

Get the Indexpath position of a point
-(Nullable Nsindexpath *) Indexpathforitematpoint: (cgpoint) point;

Get the indexpath of a cell
-(Nullable Nsindexpath *) Indexpathforcell: (Uicollectionviewcell *) cell;

Get cell from Indexpath
-(Nullable Uicollectionviewcell *) Cellforitematindexpath: (Nsindexpath *) Indexpath;

Gets an array of all visible cell
-(nsarray<__kindof uicollectionviewcell *> *) visiblecells;

Gets an array of locations for all visible cell
-(Nsarray<nsindexpath *> *) Indexpathsforvisibleitems;

The following three methods are the newly added methods in iOS9 to get the Kinsoku view
-(Uicollectionreusableview *) Supplementaryviewforelementkind: (NSString *) elementkind Atindexpath: (NSIndexPath *) Indexpath Ns_available_ios (9_0);
-(Nsarray<uicollectionreusableview *> *) Visiblesupplementaryviewsofkind: (NSString *) ElementKind NS_AVAILABLE _ios (9_0);
-(Nsarray<nsindexpath *> *) Indexpathsforvisiblesupplementaryelementsofkind: (NSString *) ElementKind NS_ Available_ios (9_0);

Slide the view to a location to drive the drawing effect
-(void) Scrolltoitematindexpath: (Nsindexpath *) Indexpath atscrollposition: (uicollectionviewscrollposition) Scrollposition animated: (BOOL) animated;

The following methods are used to dynamically add, delete, and move certain partitions to get items
-(void) Insertsections: (Nsindexset *) sections;
-(void) Deletesections: (Nsindexset *) sections;
-(void) Reloadsections: (Nsindexset *) sections;
-(void) Movesection: (nsinteger) Section tosection: (Nsinteger) newsection;

-(void) Insertitemsatindexpaths: (Nsarray<nsindexpath *> *) indexpaths;
-(void) Deleteitemsatindexpaths: (Nsarray<nsindexpath *> *) indexpaths;
-(void) Reloaditemsatindexpaths: (Nsarray<nsindexpath *> *) indexpaths;
-(void) Moveitematindexpath: (Nsindexpath *) Indexpath Toindexpath: (Nsindexpath *) Newindexpath;

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.