恶心需求又来啦!老总需要在商品列表顶部添加一个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.实现代理方法