最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS實現(xiàn)水平方向瀑布流

 更新時間:2016年08月10日 11:58:03   作者:YouXianMing  
這篇文章主要為大家詳細介紹了iOS實現(xiàn)水平方向瀑布流的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下

效果

源碼:https://github.com/YouXianMing/Animations 

//
// GridFlowLayoutViewController.m
// Animations
//
// Created by YouXianMing on 16/5/5.
// Copyright © 2016年 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];
 
 // 初始化布局文件
 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
                   collectionViewLayout: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];
 
 // 獲取數(shù)據(jù)
 [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:[NSURL 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 self.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[indexPath.row];
 
 return [Math resetFromSize:CGSizeMake(pictureModel.iwd.floatValue, pictureModel.iht.floatValue)
    withFixedHeight:_rowHeight].width;
}

@end 

細節(jié)
繼承UICollectionViewLayout

重載UICollectionViewLayout的四個方法

部分實現(xiàn)細節(jié)

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS開發(fā)仿電商類APP首頁實例

    iOS開發(fā)仿電商類APP首頁實例

    本篇文章主要介紹了iOS開發(fā)仿電商類APP首頁實例,主要是利用ui布局,具有一定的參考價值,有需要的可以了解一下。
    2016-11-11
  • iOS利用CoreImage實現(xiàn)人臉識別詳解

    iOS利用CoreImage實現(xiàn)人臉識別詳解

    OS的人臉識別從iOS 5(2011)就有了,不過一直沒怎么被關(guān)注過。人臉識別API允許開發(fā)者不僅可以檢測人臉,也可以檢測到面部的一些特殊屬性,比如說微笑或眨眼。下面這篇文章主要給大家介紹了iOS利用CoreImage實現(xiàn)人臉識別的相關(guān)資料,需要的朋友可以參考下。
    2017-05-05
  • iOS NSCache和NSUrlCache緩存類實現(xiàn)示例詳解

    iOS NSCache和NSUrlCache緩存類實現(xiàn)示例詳解

    這篇文章主要為大家介紹了iOS NSCache和NSUrlCache緩存類實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-11-11
  • iOS開發(fā)之UITableView左滑刪除等自定義功能

    iOS開發(fā)之UITableView左滑刪除等自定義功能

    今天來給大家介紹下iOS開發(fā)中UITableView左滑實現(xiàn)微信中置頂,刪除等功能。對大家開發(fā)iOS具有一定的參考借鑒價值,有需要的朋友們一起來看看吧。
    2016-09-09
  • IOS 下獲取 rootviewcontroller 的版本不同的問題解決辦法

    IOS 下獲取 rootviewcontroller 的版本不同的問題解決辦法

    這篇文章主要介紹了IOS 下獲取 rootviewcontroller 的版本不同的問題解決辦法的相關(guān)資料,希望通過本文能幫助到大家,讓大家遇到這種問題可以解決,需要的朋友可以參考下
    2017-10-10
  • 使用Xcode為iOS應(yīng)用項目創(chuàng)建PCH文件的方法及應(yīng)用示例

    使用Xcode為iOS應(yīng)用項目創(chuàng)建PCH文件的方法及應(yīng)用示例

    這篇文章主要介紹了使用Xcode為iOS應(yīng)用項目創(chuàng)建PCH文件的方法及應(yīng)用示例,PCH文件可以保留應(yīng)用的很多的基礎(chǔ)設(shè)置信息以供復(fù)用,需要的朋友可以參考下
    2016-03-03
  • 詳解iOS游戲開發(fā)中Cocos2D的坐標位置關(guān)系

    詳解iOS游戲開發(fā)中Cocos2D的坐標位置關(guān)系

    這篇文章主要介紹了iOS游戲開發(fā)中Cocos2D的坐標位置關(guān)系,Cocos2D是專門用來開發(fā)iOS游戲的開源框架,文中示例代碼采用Objective-C語言,需要的朋友可以參考下
    2016-02-02
  • iOS實現(xiàn)背景滑動效果

    iOS實現(xiàn)背景滑動效果

    這篇文章主要為大家詳細介紹了iOS實現(xiàn)背景滑動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • ios實現(xiàn)文件對比的方法

    ios實現(xiàn)文件對比的方法

    這篇文章主要介紹了ios實現(xiàn)文件對比的方法,主要是用到了filemanager,有需要的小伙伴可以參考下。
    2015-05-05
  • IOS開發(fā)之由身份證號碼提取性別的實現(xiàn)代碼

    IOS開發(fā)之由身份證號碼提取性別的實現(xiàn)代碼

    這篇文章主要介紹了IOS開發(fā)之由身份證號碼提取性別的實現(xiàn)代碼的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2016-07-07

最新評論

探索| 信丰县| 石屏县| 中卫市| 海原县| 崇阳县| 维西| 灌阳县| 邢台市| 阳朔县| 离岛区| 金湖县| 曲松县| 嵊州市| 科尔| 贵溪市| 元阳县| 青海省| 天等县| 定结县| 宁强县| 抚宁县| 永济市| 阜新市| 洞头县| 哈尔滨市| 蒙自县| 鹤庆县| 普安县| 金昌市| 万源市| 冷水江市| 广州市| 政和县| 荆门市| 上杭县| 镇赉县| 九龙城区| 清涧县| 江津市| 峡江县|