翻转单元格视图
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; }
相关文章推荐
- 【CodeForces】667A - Pouring Rain(数学)
- leetcode---Combination Sum
- spring MVC原理
- Java之十五 JDBC编程
- Java之十五 JDBC编程
- Java之十五 JDBC编程
- Non-negative Partial Sums(单调队列)
- IntelliJ IDEA中js代码报如下警告的解决方法
- Android应用架构之Retrofit使用
- Android平台的JNI开发初步
- Android Gradle查询器
- hdu1281 棋盘游戏(二分匹配+行列匹配)
- 便签3
- 【HDU】 1153 Magic Bitstrings
- 改进快排
- 30天C#基础巩固------了解委托,string练习
- 抓包工具 Wireshark 使用简介
- 哈希函数
- Python 自动刷博客浏览量
- tomcat能正常启动,但是不能访问http://localhost:8080