按单元格而不是屏幕分页 UICollectionView [英] Paging UICollectionView by cells, not screen

查看:17
本文介绍了按单元格而不是屏幕分页 UICollectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UICollectionView 具有水平滚动功能,并且在整个屏幕上总是有 2 个并排的单元格.我需要滚动停止在单元格的开头.启用分页后,集合视图会滚动整个页面,一次滚动 2 个单元格,然后停止.

I have UICollectionView with horizontal scrolling and there are always 2 cells side-by-side per the entire screen. I need the scrolling to stop at the begining of a cell. With paging enabled, the collection view scrolls the whole page, which is 2 cells at once, and then it stops.

我需要启用单个单元格滚动,或在单元格边缘停止滚动多个单元格.

I need to enable scrolling by a single cell, or scrolling by multiple cells with stopping at the edge of the cell.

我尝试继承 UICollectionViewFlowLayout 并实现方法 targetContentOffsetForProposedContentOffset,但到目前为止我只能破坏我的集合视图并且它停止滚动.有没有更简单的方法来实现这一点以及如何实现,或者我真的需要实现 UICollectionViewFlowLayout 子类的所有方法吗?谢谢.

I tried to subclass UICollectionViewFlowLayout and to implement the method targetContentOffsetForProposedContentOffset, but so far I was only able to break my collection view and it stopped scrolling. Is there any easier way to achieve this and how, or do I really need to implement all methods of UICollectionViewFlowLayout subclass? Thanks.

推荐答案

好的,所以我在这里找到了解决方案:targetContentOffsetForProposedContentOffset:withScrollingVelocity 没有子类化 UICollectionViewFlowLayout

OK, so I found the solution here: targetContentOffsetForProposedContentOffset:withScrollingVelocity without subclassing UICollectionViewFlowLayout

我应该在一开始就搜索 targetContentOffsetForProposedContentOffset.

I should have searched for targetContentOffsetForProposedContentOffset in the begining.

这篇关于按单元格而不是屏幕分页 UICollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆