UICollectionView 设置headerView部分悬停

本文介绍如何在商品列表中实现一个带有悬浮头部Banner和分类按钮的UICollectionView。通过设置UICollectionViewFlowLayout,使头部视图在滑动时保持悬浮,同时确保分类标识按钮在滚动时始终保持可见。
摘要由CSDN通过智能技术生成

恶心需求又来啦!老总需要在商品列表顶部添加一个banner,并且添加分类标识按钮,要求滑动UICollectionView的时候banner滑动,而分类标识按钮悬停(最后有图)

方法步骤:

1.先创建UICollectionView

    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];

    layout.sectionHeadersPinToVisibleBounds = YES;//头视图悬浮

    metal_collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 40, SCREEN_WDITH, 0)       collectionViewLayout:layout];

    metal_collection.backgroundColor = [UIColor clearColor];

    metal_collection.delegate = self;

    metal_collection.dataSource = self;

    metal_collection.bounces = YES;

    metal_collection.alwaysBounceVertical = YES;//数据不够也可以垂直滑动

    metal_collection.showsVerticalScrollIndicator = YES;

    [self.view addSubview:metal_collection];

    [metal_collection registerClass:[TMetalProductCell class] forCellWithReuseIdentifier:@"MetalCollectionCell"];

    [metal_collection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MetalCollectionHead"];

    [metal_collection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"MetalCollectionFooter"];

2.实现代理方法

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值