您的位置:首页 > 其它

翻转单元格视图

2016-05-26 19:50 239 查看

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: