您的位置:首页 > 其它

瀑布流接口的设计以及应用(五)

2015-07-15 22:59 387 查看
//


// ViewController.h

// 瀑布流

//

// Created by Jose on 15-7-11.

// Copyright (c) 2015年 Jose. All rights reserved.

//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end

*************************************************************************************************************

************************************************************************************************************

************************************************************************************************************

//

// ViewController.m

// 瀑布流

//

// Created by Jose on 15-7-11.

// Copyright (c) 2015年 Jose. All rights reserved.

//

#import "ViewController.h"

#import "MyWaterFlowView.h"

#import "MyWaterFlowViewCell.h"

#import "MyShop.h"

#import "MJExtension.h"

#import "MyShopCell.h"

#import "MJRefresh.h"

@interface ViewController ()<MyWaterFlowViewDataSource,MyWaterFlowViewDelegate>

/** 用于存放*/

@property(nonatomic,strong)NSMutableArray *shops;

@property(nonatomic,weak)MyWaterFlowView *mywaterflowviews;

@end

@implementation ViewController

-(NSMutableArray *)shops{

if (_shops==nil) {

self.shops=[NSMutableArray array];

}

return _shops;

}

- (void)viewDidLoad {

[super viewDidLoad];

//初始化数据

NSArray *newshops=[MyShop objectArrayWithFilename:@"2.plist"];

[self.shops addObjectsFromArray:newshops];

//瀑布流控间

MyWaterFlowView *mywaterflowview=[[MyWaterFlowView alloc]init];

//随者父控件的尺寸而自动伸缩

mywaterflowview.autoresizingMask=UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

mywaterflowview.frame=self.view.bounds;

mywaterflowview.MyDataSource=self;

mywaterflowview.MyDelegate=self;

[self.view addSubview:mywaterflowview];

self.mywaterflowviews=mywaterflowview;

//刷新瀑布流中的数据

//[mywaterflowview ReloadData];

[mywaterflowview addHeaderWithTarget:self action:@selector(LoadNewShops)];

[mywaterflowview addFooterWithTarget:self action:@selector(LoadMoreshops)];

//[mywaterflowview addHeaderWithCallback:^{}];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

//旋转屏幕刷新数据

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{

[self.mywaterflowviews ReloadData];

}

-(void)LoadNewShops{

/***

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

NSArray *newshops=[MyShop objectArrayWithFile:@"1.plist"];

[self.shops insertObjects:newshops atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, newshops.count)]];

});

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0*NSEC_PER_SEC)), dispatch_get_main_queue(),^{

[self.mywaterflowviews ReloadData];

[self.mywaterflowviews headerEndRefreshing];

});

**/

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

// 加载1.plist

NSArray *newShops = [MyShop objectArrayWithFilename:@"1.plist"];

[self.shops insertObjects:newShops atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, newShops.count)]];

});

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

// 刷新瀑布流控件

[self.mywaterflowviews ReloadData];

// 停止刷新

[self.mywaterflowviews headerEndRefreshing];

});

}

-(void)LoadMoreshops{

static dispatch_once_t onceToken;

dispatch_once(&onceToken, ^{

NSArray *moreshops=[MyShop objectArrayWithFilename:@"3.plist"];

[self.shops addObjectsFromArray:moreshops];

});

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[self.mywaterflowviews ReloadData];

[self.mywaterflowviews footerEndRefreshing];

});

}

#pragma mark 数据源方法

-(NSUInteger)NumberOfCellInWaterFlowView:(MyWaterFlowView *)mywaterflowview{

return self.shops.count;

}

-(NSUInteger)NumberOfColumsInWaterFlowView:(MyWaterFlowView *)mywateflowview{

if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) {

return 3;

}

else{

return 5;

}

}

-(MyWaterFlowViewCell *)WaterFlowViewCell:(MyWaterFlowView *)mywaterflowview CellAtIndex:(NSUInteger)index{

MyShopCell *cell=[MyShopCell cellWithWaterFlowView:mywaterflowview];

cell.shop=self.shops[index];

//cell.backgroundColor=[UIColor orangeColor];

return cell;

}

#pragma mark 代理方法

-(CGFloat)MyWaterFlowView:(MyWaterFlowView *)mywaterflowview HeightAtIndex:(NSUInteger)index{

MyShop *shop=self.shops[index];

//根据图片的宽高比返回cell的宽度

return mywaterflowview.cellWidth*shop.h/shop.w;

}

/***

-(CGFloat)MyWaterFlowView:(MyWaterFlowView *)mywaterflowview MarginType:(MyWaterFlowViewMarginType)type{

switch (type) {

case MyWaterFlowViewMarginTypeTop:

case MyWaterFlowViewMarginTypeBottom:

case MyWaterFlowViewMarginTypeLeft:

case MyWaterFlowViewMarginTypeRight:

case MyWaterFlowViewMarginTypeColumn:

case MyWaterFlowViewMarginTypeRow:

return 10;

break;

default:

return 5;

break;

}

}

-(void)MyWaterFlowView:(MyWaterFlowView *)mywaterflowview DidSelectAtIndex:(NSUInteger)index{

NSLog(@"点击了第几个%luindex",index);

}

***/

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: