#import "addressPopViewController.h"
#import <Masonry.h>
#import "addresspopviewCell.h"
#import "InterViewController.h"
#import "UIImageVIew+Tap.h"
@interface addressPopViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)NSArray *imageArray;
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,strong)UIImageView *changePicture;
@property(nonatomic,strong)UIView *downView;
@property(nonatomic,strong)UILabel *changecityLabel;
@property(nonatomic,strong)UIView *upView;
@property(nonatomic,strong)UICollectionView *groundCollectionView;
@property(nonatomic,strong)addressPopViewController *addressPop;
@property(nonatomic,strong)InterViewController *interView;
@property(nonatomic,assign)BOOL isOpen;
@end
@implementation addressPopViewController
-(addressPopViewController *)addressPop{
if (!_addressPop) {
_addressPop = [[addressPopViewController alloc]init];
_addressPop.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}
return _addressPop;
}
//重写Cell的初始化方法,在初始化时 添加一个Label
- (void)viewDidLoad {
[super viewDidLoad];
_isOpen = NO;
self.view.backgroundColor = [UIColor clearColor];
_downView = [[UIView alloc]init];
_downView.backgroundColor = [UIColor redColor];
[self.view addSubview:_downView];
[_downView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.height.mas_equalTo(40);
make.bottom.mas_equalTo(0);
}];
_changePicture = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"dgn-gr-yp-zwss(dzxz)2"]];
[_changePicture addTapGestureRecognizerWith:self action:@selector(clickChange:)];
[_downView addSubview:_changePicture];
[_changePicture mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(_downView.mas_centerX).multipliedBy(0.7);
make.size.mas_equalTo(CGSizeMake(35/2, 35/2));
make.centerY.mas_equalTo(_downView.mas_centerY);
}];
_changecityLabel=[[UILabel alloc]init];
_changecityLabel.textColor=[UIColor blackColor];
_changecityLabel.text = @"切换城市";
_changecityLabel.textColor = [UIColor whiteColor];
_changecityLabel.textAlignment=NSTextAlignmentCenter;
_changecityLabel.lineBreakMode=NSLineBreakByCharWrapping;
_changecityLabel.numberOfLines=0;
_changecityLabel.font=[UIFont systemFontOfSize:18];
[_downView addSubview:_changecityLabel];
[_changecityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(_downView.mas_centerY);
make.left.mas_equalTo(_changePicture.mas_right).offset(10);
}];
_downView = [[UIView alloc]init];
_downView.backgroundColor = [UIColor blueColor];
[self.view addSubview:_downView];
[_downView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.bottom.mas_equalTo(0);
make.height.mas_equalTo(40);
}];
_upView = [[UIView alloc]init];
[self.view addSubview:_upView];
[_upView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.bottom.mas_equalTo(_downView.mas_top);
}];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
_collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64+324/3+15, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:flowLayout];
flowLayout.itemSize = CGSizeMake(_upView.frame.size.width/2.5,_upView.frame.size.width/2.5);
flowLayout.minimumLineSpacing = 1;
flowLayout.minimumInteritemSpacing = 1;
flowLayout.sectionInset = UIEdgeInsetsMake(1, 1, 1, 1);
_collectionView.backgroundColor = [UIColor colorWithRed:236.0/255 green:241.0/255 blue:238.0/255 alpha:1];
[_upView addSubview:_collectionView];
[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.bottom.mas_equalTo(0);
}];
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[addresspopViewCell class] forCellWithReuseIdentifier:@"addresspopViewCell"];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 20;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
addresspopViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"addresspopViewCell" forIndexPath:indexPath];
cell.cellLabel.text = @(indexPath.row +1).stringValue;
return cell;
}
//定义分区距离四边缘的距离
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(1, 1, 1, 1);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGFloat width =( _upView.frame.size.width -10)/2;
return CGSizeMake(width, width/8);
}
#pragma mark UICollectionView被选中时调用的方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"选择%ld",(long)indexPath.item);
}
-(void)clickChange:(UITapGestureRecognizer *)sender{
NSLog(@"点击的是切换城市");
[self dismissViewControllerAnimated:YES completion:nil];
}
@end