翻转单元格视图

collectionView的宽度<每次翻过的宽度

1改变collectionView的宽度为加上间隙宽度
2打开分页属性
//覆写初始化时
- (instancetype)initWithFrame:(CGRect)frame {
    //创建布局条件
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //设置水平间隙
    flowLayout.minimumLineSpacing = BlockWidth;
    //改变collectionView的宽度为加上间隙宽度
    frame.size.width += BlockWidth;
    //调用父类初始化
    self = [super initWithFrame:frame collectionViewLayout:flowLayout];
    if(self){
    //并且打开分页属性
    self.pagingEnabled = YES;
    }
    return self;
}

collectionView的宽度>每次翻过的宽度

//覆写该方法
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {

    //获取偏移的下标
    CGFloat xOffset = targetContentOffset->x;
    //求出翻转一次的宽度(单元格宽度+水平或者竖直间隙宽度)
    CGFloat width = cell.width + minimumLineSpacing;
    //计算滑动停止时偏移了几次
    CGFloat index = xOffset / width;
    //翻过半页即认为到下一页
    NSInteger indexInteger = index + 0.5;
    //强行改变偏移的下标
    targetContentOffset->x = indexInteger * width;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值