Uicollectionview was introduced in 2012, is not a new technology, here just to do a simple implementation.
Collection View: Uicollectionview
Like Uicollectionview and UITableView, it is also the DataSource and delegate design pattern: DataSource provides the data source for the view, tells the view what to display, and how to show them, Delegate provides some styling details as well as the response of the user interaction.
In CollectionView, the layout of the cell is more complex, specifically, to make the. class to describe the layout and behavior of CollectionView, this is uicollectionviewlayout. Uicollectionviewlayout is an abstract base class that, when used, creates new objects with its subclasses. The most commonly used uicollectionviewlayout subclass is Uicollectionviewflowlayout (provided by Apple). Flow layout is simply a line-aligned layout, which can be done with a waterfall flow style like the Youku client. Of course Uicollectionviewlayout also has other interesting subcategories such as stacked layouts, circular layouts,Cover Flow layouts, and so on.
Here you use the uicollectionviewflowlayout to implement a video player layout. The data analysis of the people can ignore or add their own desired pictures, etc., mainly about the formation of layout.
Environment: Xcode6,arc, Pure code
Viewdidload method
Register the class//header view that you want to use in Viewdidload [_collectionview Registerclass:[headview class] Forsupplementaryviewofkind:uicollectionelementkindsectionheader withreuseidentifier:@ "header"]; Item (cell) with scrolling picture [_collectionview Registerclass:[scrollcollectionviewcell class] forcellwithreuseidentifier:@ "Scrollcell"]; Single picture of item (cell) [_collectionview Registerclass:[customcollectionviewcell class] Forcellwithreuseidentifier: @ "Cell"];
Other methods in Viewcontroller
#pragma mark Collection View//Returns the item number per partition-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView Numberofitemsinsection: (Nsinteger) section{if (section==0) {return 1; } nsstring*category=[_allcategory Objectatindex:section]; if ([_allvideodic objectforkey:category]) {return [[_allvideodic objectforkey:category] count]; }else return 0;} Generate item-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: ( Nsindexpath *) indexpath{//The first partition has only one item and differs from other partitions if (indexpath.section==0) {Scrollcollectionviewcell*scroll Cell=[collectionview dequeuereusablecellwithreuseidentifier:@ "Scrollcell" Forindexpath:indexpath]; [Scrollcell initwitharray:[_allvideodic objectforkey:@ "ad"]; return Scrollcell; }else{//Other partitions Customcollectionviewcell*cell=[collectionview dequeuereusablecellwithreuseidentifier:@ "Cell" Forindexpath:indexpath]; Videomodel*video=[[_allvideodic objectforkey:[_allcategory ObjectatinDex:indexpath.section]]objectatindex:indexpath.row]; [Cell Initdatawith:video]; return cell; } return nil;} Returns the size of item-(cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (Uicollectionviewlayout *) Collectionviewlayout Sizeforitematindexpath: (Nsindexpath *) indexpath{if (indexpath.row==0&& indexpath.section==0) {return Cgsizemake (Width, 200); } return Cgsizemake (80, 130);} Number of partitions returned-(Nsinteger) Numberofsectionsincollectionview: (Uicollectionview *) collectionview{return [_allcategory Count ];} Returns the size of the Headerview-(cgsize) CollectionView: (Uicollectionview *) CollectionView layout: (Uicollectionviewlayout *) Collectionviewlayout referencesizeforheaderinsection: (Nsinteger) section{if (section==0) {return CGSizeMake (Wid Th, 0); }else return Cgsizemake (Width, 20);} Returns the headerview-(Uicollectionreusableview *) of each partition CollectionView: (Uicollectionview *) CollectionView Viewforsupplementaryelementofkind: (NSString *) kind Atindexpath: (Nsindexpath *) indexpath{if (Indexpath.section!=0&&[kind Isequaltostring:uicollectionelementkindsectionheader]) {Stati C nsstring *[email protected] "header"; Headview*view=[collectionview Dequeuereusablesupplementaryviewofkind:kind Withreuseidentifier:reuseidentifier Forindexpath:indexpath]; Nsstring*title; Switch (indexpath.section) {Case 1: [email protected] "Recommended Today"; Break Case 2: [email protected] "domestic micro-shadow"; Break Case 3: [email protected] "International micro-shadow"; Break Default:break; } View.title=title; return view; } return nil; }
:
[iOS advanced] uicollectionview to achieve waterfall streaming effect