Effect
Source: Https://github.com/YouXianMing/Animations
GRIDFLOWLAYOUTVIEWCONTROLLER.M//animations////Created by youxianming on 16/5/5. COPYRIGHT©2016 year youxianming.
All rights reserved. #import "GridFlowLayoutViewController.h" #import "uiview+setrect.h" #import "GridLayout.h" #import "FlowStyleCell.h
"#import" FileManager.h #import "nsstring+md5.h" #import "Nsdata+jsondata.h" #import "ResponseData.h" #import "MATH.H"
#import "GCD.h" static nsstring *picturessource = @ "http://www.duitang.com/album/1733789/masn/p/0/50/"; @interface Gridflowlayoutviewcontroller () <uicollectionviewdatasource, Uicollectionviewdelegate,
Gridlayoutdelegate> @property (nonatomic, strong) Uicollectionview *collectionview;
@property (nonatomic) cgfloat rowHeight;
@property (nonatomic, strong) Nsmutablearray *datas;
@property (nonatomic, strong) ResponseData *picturesdata;
@property (nonatomic, strong) Nsmutablearray <waterfallpicturemodel *> *datasource;
@end @implementation Gridflowlayoutviewcontroller-(void) Setup { [Super Setup];
_datasource = [Nsmutablearray new];
Initialize the layout file cgfloat gap = 1;
Nsinteger rowcount = arc4random ()% 3 + 2;
_rowheight = (Self.contentView.height-(rowcount + 1) * gap)/(cgfloat) rowcount;
GridLayout *layout = [GridLayout new];
Layout.manager.edgeInsets = Uiedgeinsetsmake (Gap, Gap, Gap, Gap);
Layout.manager.gap = Gap;
Layout.delegate = self;
Nsmutablearray *rowheights = [Nsmutablearray array];
for (int i = 0; i < rowcount i++) {[Rowheights addobject:@ (_rowheight)];
} layout.manager.rowHeights = Rowheights; Self.collectionview = [[Uicollectionview alloc] InitWithFrame:self.contentView.bounds Collection
Viewlayout:layout];
Self.collectionView.delegate = self;
Self.collectionView.dataSource = self;
Self.collectionView.backgroundColor = [Uicolor Clearcolor];
Self.collectionView.showsHorizontalScrollIndicator = NO;
Self.collectionView.alpha = 0; [Self.collectionview registerclass:[fLowstylecell class] forcellwithreuseidentifier:@ "Flowstylecell"];
[Self.contentview AddSubview:self.collectionView];
Get data [gcdqueue executeinglobalqueue:^{nsstring *string = [Picturessource lowermd532bitstring];
NSString *realfilepath = [FileManager therealfilepath:[nsstring stringwithformat:@ "~/Documents/%@", string]];
NSData *data = nil; if ([filemanager fileexistwithrealfilepath:realfilepath] = NO) {data = [[NSData alloc] Initwithcontentsofurl:[nsu
RL Urlwithstring:picturessource]];
[Data Writetofile:realfilepath Atomically:yes];
else {data = [NSData Datawithcontentsoffile:realfilepath];
} nsdictionary *datadic = [data Tolistproperty];
[Gcdqueue executeinmainqueue:^{self.picturesdata = [[ResponseData alloc] initwithdictionary:datadic]; if (Self.picturesData.success.integerValue = = 1) {for (int i = 0; i < Self.picturesData.data.blogs.count; i++ ) {[_datasource addObject:self.picturesDaTa.data.blogs[i]];
} [_collectionview Reloaddata];
[UIView animatewithduration:0.5f animations:^{_collectionview.alpha = 1.f;
}];
}
}];
}]; }-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (NSInteger) Section {return s
Elf.dataSource.count; }-(Uicollectionviewcell *) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (NSIndexPath *)
Indexpath {Waterfallpicturemodel *picturemodel = _datasource[indexpath.row]; Flowstylecell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:@ "Flowstylecell" ForIndexPath:
Indexpath];
Cell.indexpath = Indexpath;
Cell.data = Picturemodel;
Cell.rowheight = _rowheight;
[Cell loadcontent];
return cell; }-(CGFloat) Itemwidthwithindexpath: (Nsindexpath *) Indexpath {Waterfallpicturemodel *picturemodel = _dataSource[index
Path.row]; return [Math resetfromsize:cgsizemake (PictureModel.iwd.floatValue, PictureModel.iht.floatValue)
Withfixedheight:_rowheight].width;
} @end
Details
Inherit Uicollectionviewlayout
Four ways to Overload Uicollectionviewlayout
Partial Implementation Details
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.