欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2016年08月10日 11:58:03   作者:YouXianMing  
這篇文章主要為大家詳細(xì)介紹了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 

細(xì)節(jié)
繼承UICollectionViewLayout

重載UICollectionViewLayout的四個方法

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

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

相關(guān)文章

  • iOS實現(xiàn)百度外賣頭像波浪的效果

    iOS實現(xiàn)百度外賣頭像波浪的效果

    對于現(xiàn)在很多人來說,叫外賣就成了不可或缺的習(xí)慣。某日瞬間發(fā)現(xiàn)百度外賣的APP波浪效果很是吸引人,相比較其他的外賣APP,顏值略高些.(淘寶也有波浪的效果),遂就思考如何實現(xiàn)這種"浪"的效果,下面來一起看看。
    2016-08-08
  • iOS開發(fā)之如何給View添加指定位置的邊框線詳解

    iOS開發(fā)之如何給View添加指定位置的邊框線詳解

    這篇文章主要給大家介紹了iOS開發(fā)之如何給View添加指定位置的邊框線的相關(guān)資料,給view加邊框很容易,重點是如何給指定邊框加邊框,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-10-10
  • iOS獲取某個日期后n個月的日期

    iOS獲取某個日期后n個月的日期

    這篇文章主要介紹了iOS獲取某個日期后n個月的日期的相關(guān)資料,需要的朋友可以參考下
    2017-08-08
  • ios app重提提交審核流程

    ios app重提提交審核流程

    本篇文章給大家講述了在APP第一次沒有審核通過后,重新提交的流程和注意的地方,學(xué)習(xí)一下吧。
    2017-12-12
  • iOS實現(xiàn)文件切片儲存并且上傳(仿斷點續(xù)傳機制)

    iOS實現(xiàn)文件切片儲存并且上傳(仿斷點續(xù)傳機制)

    這篇文章主要給大家介紹了關(guān)于iOS實現(xiàn)文件切片儲存并上傳仿斷點續(xù)傳機制的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-12-12
  • iOS時鐘開發(fā)案例分享

    iOS時鐘開發(fā)案例分享

    這篇文章主要為大家分享了iOS時鐘開發(fā)案例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-04-04
  • iOS中的UITableView的重用機制與加載優(yōu)化詳解

    iOS中的UITableView的重用機制與加載優(yōu)化詳解

    本篇文章主要介紹了iOS中的UITableView的重用機制與加載優(yōu)化詳解,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-02-02
  • iOS漸變圓環(huán)旋轉(zhuǎn)動畫CAShapeLayer CAGradientLayer

    iOS漸變圓環(huán)旋轉(zhuǎn)動畫CAShapeLayer CAGradientLayer

    這篇文章主要介紹了iOS漸變圓環(huán)旋轉(zhuǎn)動畫CAShapeLayer CAGradientLayer的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • iOS實現(xiàn)微信/QQ顯示最近拍攝圖片的功能實例代碼

    iOS實現(xiàn)微信/QQ顯示最近拍攝圖片的功能實例代碼

    如果你剛剛拍攝了圖片,在使用微信/QQ發(fā)生消息時會顯示“你可能要發(fā)送的圖片”,這個功能非常人性化,怎么實現(xiàn)的呢?下面小編給大家分享iOS實現(xiàn)微信/QQ顯示最近拍攝圖片的功能實例代碼,一起看看吧
    2017-03-03
  • iOS?GCD之dispatch_group_enter和dispatch_group_leave使用

    iOS?GCD之dispatch_group_enter和dispatch_group_leave使用

    這篇文章主要為大家介紹了iOS?GCD之dispatch_group_enter和dispatch_group_leave使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-03-03

最新評論