[英]Paging with left inset on small cells in UICollectionView
I have a UICollectionView filled with dates ranging from one date to another.我有一个 UICollectionView 填充了从一个日期到另一个日期的日期。 I have implemented the UICollectionView with IGListKit.
我已经用 IGListKit 实现了 UICollectionView。 I would Like to enable paging on each cell so that each cell will land in the middle of the circle when it scrolls past it.
我想在每个单元格上启用分页,以便每个单元格在滚动时会落在圆圈的中间。 (Like below) I have tried a few ways of paging, but these don't centre directly in the middle of the circle (As seen in the second image).
(如下所示)我尝试了几种分页方法,但这些方法不会直接居中在圆圈中间(如第二张图片所示)。 What is happening is, the cells are getting paged to the left-hand side, I would like there to be an inset of 20 so that it fits into the circle
发生的事情是,单元格被分页到左侧,我希望有一个 20 的插图,以便它适合圆圈
To enable the current date to show on the left-hand side in the circle when the view first loads, I have the semantic set to Force Right-to-Left
and I also have edgeInsets which are:为了在视图首次加载时使当前日期显示在圆圈的左侧,我将语义设置为
Force Right-to-Left
并且我还有 edgeInsets,它们是:
left: screenWidth-62, right: 20)
The width of the cell is 42 and the inset at the side is 20, therefore the first cell will sit in the circle with these insets.单元格的宽度为 42,侧面的插图为 20,因此第一个单元格将位于带有这些插图的圆圈中。 So when the view first loads, the collection view looks like this:
所以当视图第一次加载时,集合视图看起来像这样:
I basically want each cell to land inside of this circle when it scrolls past (if the scrolling stops)我基本上希望每个单元格在滚动时落在这个圆圈内(如果滚动停止)
This is what I have so far:这是我到目前为止:
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if scrollView == self.collectionView {
var currentCellOffset = self.collectionView.contentOffset
currentCellOffset.x += (self.collectionView.frame.width / 2) + 20
if let indexPath = self.collectionView.indexPathForItem(at: currentCellOffset) {
self.collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
}
}
}
and this:和这个:
collectionView.decelerationRate = UIScrollView.DecelerationRate.fast
Does anyone know how to solve this?有谁知道如何解决这个问题?
Thank you谢谢
i created a custom collection view layout for paging by cell instead of screen我创建了一个自定义集合视图布局,用于按单元而不是屏幕进行分页
i also outline a few different ways to customize it with examples in the README我还概述了一些不同的方法来自定义它与 README 中的示例
let me know if you have any questions about it or need more help如果您对此有任何疑问或需要更多帮助,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.