瀑布流接口的设计以及应用(五)
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
// 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
相关文章推荐
- HttpServletResponse对象(一)
- 13.Java5条件阻塞Condition的应用
- SQLite数据库
- [leetcode] Search for a Range
- centos 重启网站服务器 httpd
- L3:==、java.lang.Object 类、toString()
- C语言函数之可变参数原理:va_start、va_arg及va_end
- Quartz2D
- 瀑布流接口的设计以及应用(四)
- 简化通知中心的使用
- Android -- Volley解析
- linux系统时间同步,硬件时钟和系统时间同步,时区的设置
- 二分查找法及其应用
- java的myeclipse,java页面修改默认的javadoc方法
- jquery 连接在div中显示
- android 游戏sdk嫁接方式
- ORACLE中创建表空间,创建表,修改表,授权
- 40岁应该学会的是面对和取舍
- java网络编程(1)
- Eclipse中设置ButterKnife进行注解式开发步骤