//
// ShopListMainViewController.m
// WeiLi
//
// Created by 张立志 on 16/10/13.
// Copyright © 2016年 张立志. All rights reserved.
//
#import "ShopListMainViewController.h"
#import "ConstantHeader.h"
#import <Masonry/Masonry.h>
#import "OJLWaterLayout.h"
#import "MBProgressHUD+QSJ.h"
#import "AlertUtil.h"
#import "MJRefresh.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import <SDCycleScrollView/SDCycleScrollView.h>
#import "Model.h"
#import "DynamicExperienceCell.h"
@interface ShopListMainViewController ()<UICollectionViewDataSource, UICollectionViewDelegate,OJLWaterLayoutDelegate>
//@property(nonatomic,strong) UIScrollView *mainScrollView;
@property(nonatomic,strong) UIView *contentView;
@property (nonatomic, strong) UICollectionView* collectionView;
@property (nonatomic, strong) NSMutableArray* modelArray;
@property (nonatomic, strong) OJLWaterLayout* layout;
@end
@implementation ShopListMainViewController
- (NSMutableArray *)modelArray
{
if (!_modelArray) {
_modelArray = [[Model models] mutableCopy];
}
return _modelArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
// self.mainScrollView = [[UIScrollView alloc]init];
// [self.view addSubview:self.mainScrollView];
// self.mainScrollView.showsHorizontalScrollIndicator = NO;
// self.mainScrollView.showsVerticalScrollIndicator = NO;
// self.mainScrollView.bounces = NO;
// self.mainScrollView.backgroundColor = NORMAL_BKG_GREY;
// self.mainScrollView.scrollEnabled = YES;
// [self.mainScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
// make.edges.mas_equalTo(self.view);
// }];
//今日推荐的商品main
OJLWaterLayout* layout = [[OJLWaterLayout alloc] init];
self.layout = layout;
layout.numberOfCol = 2;
layout.rowPanding = 7;
layout.colPanding = 7;
layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
layout.delegate = self;
[layout autuContentSize];
//添加collection
self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, SCREEN_SIZE_HEIGHT, SCREEN_SIZE_WIDTH,SCREEN_SIZE_HEIGHT-49-64-40) collectionViewLayout:self.layout];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
self.collectionView.backgroundColor = NORMAL_BKG_GREY;
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
//注册cell
[self.collectionView registerClass:[DynamicExperienceCell class] forCellWithReuseIdentifier:@"cell"];
//用contentView撑
self.contentView = [[UIView alloc] init];
[self.collectionView addSubview:self.contentView];
//
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(self.collectionView.mas_width);
make.bottom.mas_equalTo(0);
}];
//轮播图
UIView *lunBoView = [[UIView alloc]init];
[self.contentView addSubview:lunBoView];
lunBoView.backgroundColor = [UIColor yellowColor];
[lunBoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView);
make.left.mas_equalTo(self.contentView);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(SCREEN_SIZE_WIDTH*2/5);
}];
//轮播图下面热销商品的标题
UIView *reXiaoTitleView = [[UIView alloc]init];
reXiaoTitleView.backgroundColor = NORMAL_BKG_GREY;
[self.contentView addSubview:reXiaoTitleView];
[reXiaoTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(lunBoView.mas_bottom);
make.left.mas_equalTo(self.contentView);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(40);
}];
// UIView *lineOne = [[UIView alloc]init];
UIView *reXiaoView = [[UIView alloc]init];
[self.contentView addSubview:reXiaoView];
reXiaoView.backgroundColor = [UIColor yellowColor];
[reXiaoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(reXiaoTitleView.mas_bottom);
make.left.mas_equalTo(self.contentView);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(SCREEN_SIZE_WIDTH*2/5);
}];
//下面活动专区商品的标题
UIView *activityTitleView = [[UIView alloc]init];
activityTitleView.backgroundColor = NORMAL_BKG_GREY;
[self.contentView addSubview:activityTitleView];
[activityTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(reXiaoView.mas_bottom);
make.left.mas_equalTo(self.contentView);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(40);
}];
UIView *activityView = [[UIView alloc]init];
[self.contentView addSubview:activityView];
activityView.backgroundColor = [UIColor yellowColor];
[activityView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(activityTitleView.mas_bottom);
make.left.mas_equalTo(self.contentView);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(SCREEN_SIZE_WIDTH*2/5);
}];
//今日推荐的商品的标题
UIView *todayTitleView = [[UIView alloc]init];
todayTitleView.backgroundColor = NORMAL_BKG_GREY;
[self.contentView addSubview:todayTitleView];
[todayTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(activityView.mas_bottom);
make.left.mas_equalTo(self.contentView);
make.width.mas_equalTo(SCREEN_SIZE_WIDTH);
make.height.mas_equalTo(40);
}];
[self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(self.collectionView.mas_width);
make.bottom.mas_equalTo(todayTitleView.mas_bottom);
}];
//内容详细偏移
self.collectionView.contentOffset = CGPointMake(0, (SCREEN_SIZE_WIDTH*2/5 +40)*3);
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark UICollectionViewDataSource, UICollectionViewDelegate
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.modelArray.count;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
DynamicExperienceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
// cell.model = self.modelArray[indexPath.item];
if (indexPath.row == 0) {
cell.personNameLabel.text = @"asdfasdfasdfasfd";
cell.agreeNumLabel.text = @"1111111111111";
}else{
cell.personNameLabel.text = @"张三";
cell.agreeNumLabel.text = @"111111";
}
[cell setNeedsLayout];
[cell layoutIfNeeded];
return cell;
}
#pragma mark OJLWaterLayoutDelegate
-(CGFloat)OJLWaterLayout:(OJLWaterLayout *)OJLWaterLayout itemHeightForIndexPath:(NSIndexPath *)indexPath{
Model* model = self.modelArray[indexPath.item];
CGFloat width = ([UIScreen mainScreen].bounds.size.width - self.layout.sectionInset.left - self.layout.sectionInset.right - (self.layout.colPanding * (self.layout.numberOfCol - 1))) / self.layout.numberOfCol;
//H现 = ( W现 / W网 )* H网
//图片高度
CGFloat height = (width/[model.w floatValue])*[model.h floatValue];
//这里面计算好各项高度值
//title
CGRect titleHeighR = [model.name boundingRectWithSize:CGSizeMake(width-2*TEXT_LINE_DISTANCE-3, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:LITTLE_FONT} context:nil];
CGFloat titleHeignt = titleHeighR.size.height+6;
//文字内容
CGRect titleContentHeighR = [model.des boundingRectWithSize:CGSizeMake(width-2*TEXT_LINE_DISTANCE-3, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:LITTLE_FONT} context:nil];
CGFloat titleContentHeignt = titleContentHeighR.size.height+6;
//还要加上人头像
height = height +titleHeignt+titleContentHeignt+(30+TEXT_LINE_DISTANCE*3);
return height;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end