招骋地址弹出按钮

本文介绍了一个使用UICollectionView展示图片和切换城市的iOS应用界面实现方法。通过自定义UICollectionView的布局,实现了图片展示区的特定布局效果,并添加了切换城市的交互功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值