It is now known that when initializing the Uicollectionview, you must pass in a layout object to manage it. This is also the obvious difference between CollectionView and TableView, through the collectionviewlayout, can be more powerful control of the CollectionView.
Customize a uicollectionviewflowlayout, re-inside the several methods.
Method One: Each sliding CollectionView calls this method and asks whether to re-layout. If Returen Yes, method Two and method three are called.
-(BOOL) Shouldinvalidatelayoutforboundschange: (CGRect) newbounds{
//
return YES;
}
Method Two:
-(void) preparelayout{
[Super Preparelayout];
Here, you can make some other changes before layout. or not doing anything.
}
Method Three: In this method, you can obtain a layout attribute to all cells that are ready to be refreshed: uicollectionviewlayoutattributes, through this attributes, you can change the cell's Size,frame, The layout properties of Alpha and so on.
-(nsarray<uicollectionviewlayoutattributes *> *) Layoutattributesforelementsinrect: (CGRect) rect{
Call the method of the parent class to get.
Nsarray *array = [Super Layoutattributesforelementsinrect:rect];
Calculates the X-value of the CollectionView center point
CGFloat CenterX = self.collectionview.contentoffset.x + self.collectionView.frame.size.width * 0.5;
Based on the original layout properties, fine-tune
For (uicollectionviewlayoutattributes *attrs in array) {
The space between the X-values of the center point X and the CollectionView center point of the cell
CGFloat delta = ABS (Attrs.center.x-centerx);
Calculates the scale of the cell based on the spacing value
CGFloat scale = 1-delta/self.collectionview.frame.size.width;
Set the zoom ratio
Attrs.transform = Cgaffinetransformmakescale (scale, scale);
}
return array;
}
Method Four: After each hand slide, it will be called. Is the instant call that the hand leaves the screen. Return a final offset, if you want to change it, set it here. If you do not change it, return directly to Proposedcontentoffset.
-(Cgpoint) Targetcontentoffsetforproposedcontentoffset: (cgpoint) Proposedcontentoffset withScrollingVelocity: ( Cgpoint) velocity{
return proposedcontentoffset;
}
Here is the one I made, the cell did not put the picture up, directly with the color tag: the same reason, waterfall flow is so. The wrong place, hope to advise
Use Uicollectionviewflowlayout for layout in Uicollectionview (imitate Apple album)