简体   繁体   English

在 UICollectionView 中的小单元格上使用左插入进行分页

[英]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 中的示例

check it out here在这里查看

let me know if you have any questions about it or need more help如果您对此有任何疑问或需要更多帮助,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于分页 UICollectionView 的居中单元格 - Centering cells for paging UICollectionView 启用分页时,UICollectionView使隐藏的单元出队 - UICollectionView dequeues hidden cells when paging is enabled 将空的uitableviewcells(占位符单元格)的左插图设置为0以消除左填充? - Setting left inset of empty uitableviewcells (placeholder cells) to 0 to eliminate left padding? UICollectionView水平分页仅在首页上每行显示3个单元格 - UICollectionView horizontal paging presenting 3 cells per row on first page only UIScrollView Paging Inset无法正常工作 - UIScrollView Paging Inset not working 如何从右到左而不是从左到右显示 UICollectionView 的单元格? - How to display cells of UICollectionView from right to left instead of left to right? 类似日历的 UICollectionView - 如何仅在第一项之前添加左插图? - Calendar-like UICollectionView - how to add left inset before first item only? 在不使用自定义布局的情况下左对齐 UICollectionView 单元 - Left aligning UICollectionView Cells without using Custom Layout 如何使用 UICollectionView 在单元格左侧创建部分和标题? - How to create sections along with headers on the left of cells with UICollectionView? UICollectionView水平分页布局 - UICollectionView horizontal paging layout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM