关于使用UICollectionViewCompositionalLayout来做两边多出一点的轮播图

关于使用UICollectionViewCompositionalLayout来做两边多出一点的轮播图

在ios13之前,做一个两边漏出一点的轮播图,设置pagingenable不好使,必须得重写一些代理来实现

但是这种实现方法有个问题,就是滑动的时候会有一些不可避免的卡顿现象

具体实现方法可以百度,这里说说新的方法


UICollectionviewCompositionalLayout

继承于uicollectionviewflowlayout

需要设置config和section

大神ninjia的文章说的很全面

https://www.jianshu.com/p/df2bbdd98377


这里做一个补充说明


pragma mark - 每一个item的大小

CGFloat bannerSize = [UIScreen mainScreen].bounds.size.width - 130;//原本占screenwidth-30


pragma mark - 高度和宽度比例

NSCollectionLayoutSize *bannerItemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension fractionalHeightDimension:1]];

NSCollectionLayoutItem *bannerItem = [NSCollectionLayoutItem itemWithLayoutSize:bannerItemSize];


pragma mark - item之间的间距

bannerItem.contentInsets = NSDirectionalEdgeInsetsMake(0, 15, 0, 15);//左右各收缩5像素 占screenwidth-40


pragma mark - 组的大间距

NSCollectionLayoutSize *bannerGroupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:bannerSize] heightDimension:[NSCollectionLayoutDimension absoluteDimension:bannerSize/2]];


group = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:bannerGroupSize subitem:bannerItem count:1];//水平

pragma mark - 顶部的间距

NSCollectionLayoutSize *headerSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension fractionalWidthDimension:1.0] heightDimension:[NSCollectionLayoutDimension estimatedDimension:0]];


pragma mark - 对其方式

NSCollectionLayoutBoundarySupplementaryItem *headerItem = [NSCollectionLayoutBoundarySupplementaryItem boundarySupplementaryItemWithLayoutSize:headerSize elementKind:UICollectionElementKindSectionHeader alignment:NSRectAlignmentTop];

你可能感兴趣的:(关于使用UICollectionViewCompositionalLayout来做两边多出一点的轮播图)