- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图让 UICollectionView 快速回到靠近它的任何项目单元格的中心,但问题是,当我稍微移动它时,它会以太快的速度弹回单元格的中心,而单元格的中心看起来并不光滑,是否可以忽略或禁用滚动,除非用户滑动到下一个项目并且不让 ScrollView 将其捕捉到同一项目?
这是我的捕捉代码
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let layout = self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout
let cellWidthIncludingSpacing = layout.itemSize.width + layout.minimumLineSpacing
var offset = targetContentOffset.pointee
let index = (offset.x + scrollView.contentInset.left ) / cellWidthIncludingSpacing
let roundedIndex = round(index)
self.lastContentOffset = scrollView.contentOffset.x
offset = CGPoint(x: roundedIndex * cellWidthIncludingSpacing - scrollView.contentInset.left, y: -scrollView.contentInset.top)
targetContentOffset.pointee = offset
}
编辑:这就是它从物理设备恢复的方式。这里速度较慢,因为它是 gif
最佳答案
它会弹回来,因为您直接设置了 contentOffset。相反,您应该调用 UIScrollViewMethod setContentOffset(_:animated:)动画是真实的。如果您仍然不喜欢结果,请考虑实现 UICollectionLayout 方法 targetContentOffsetForProposedContentOffset:withScrollingVelocity:然后布局将自动捕捉到您返回的点。
关于ios - Swift - 如果项目滚动一点,UICollection 回弹得太快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55146146/
我有这门课,我将在顶部菜单 View 上工作。 这是代码: import UIKit class TopHomeMenuBar: UIView { let collectionView: UIColl
我正在尝试创建一个包含两列的表格,其中偶数行比奇数行高。这就是我目前拥有的。 import UIKit class FBSCollectionViewCell: UICollectionViewCel
我创建了一个具有自定义布局的 UICollection,以允许垂直和水平滚动。它是一个由相等的部分和每个部分中的项目组成的网格(即 10 x 10、20 x 20 等)。我希望能够放置两个保留在 Vi
Collection View 单元中有一个按钮,当我单击该按钮时,目标是转到更详细的 View Controller 。 class WelcomeViewController: UIViewCo
我正在尝试制作可以过滤 UICollectionView 搜索结果的搜索栏。我制作了一个自定义 UICollectionViewCell 类 class toolCollectionViewCell:
我制作了一个 UICollection View 。在我的 ViewController 中,我有以下代码: import UIKit import AlamofireImage class MYVi
你好,我正在使用 UICollectionView 在我的 iPhone 应用程序中显示图像,但是当我 ScrollView 时,加载的图像消失并再次加载图像,这是因为“dequeueReusable
我正在使用 UICollectionView 来存储图像,我可以通过覆盖 CanMove 和 MoveItem 来重新排序它们。 但 UICollection 中的项目只有在单元格尺寸较大时才会重新排
我创建了一个自定义 UICollection 单元格,但数据有时会出现在错误的单元格中,无论我刷新多少 UICollection View ,它都拒绝更改。我已经打印出来,看看从数组中获取的数据是否有
我在我的应用程序中添加了一个 UICollectionView。我已经给出了它的约束,例如 Collection View 的前导、尾随、顶部和一些固定高度。它正在显示所有项目。但我无法滚动它。请问是
我正在尝试动态更新 uicollectionview。我用了this amazing tutorial关于如何创建简单的 uicollection。 它在使用静态项目数组时效果很好。我的问题 - 我想
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我制作了一个仅包含 2 个单元格的 UICollection,其页脚包含一个按钮“显示更多”。当我们点击按钮“显示更多”时,它应该在 UICollection 中追加 2 个单元格。 我的问题是,当我
默认情况下,当您在 Collection View 中使用流布局时,单元格垂直居中。有没有办法改变这种对齐方式? 最佳答案 采用面向功能的方法的 Swift 4: class TopAlignedCo
目前我有一个 collection view,它占据了 3.5 英寸屏幕尺寸的大部分屏幕。collection view 距离屏幕顶部 51 像素,距离屏幕底部 20 像素。我将单元格与 UIPage
我遇到以下问题: 我有一个带有 UICollection View 的 View Controller ,文本数据(名称、图像的 url)来自使用 swiftyJSON 的 json,但所有图像都是以
每次打开具有 Collection View 的 View Controller 时,我都会收到以下消息 [ setValue:forUndefinedKey:]: this class is not
我需要在导航回该特定 View 时重新加载 Collection View 。 我尝试实现以下所有内容,但它不起作用 1.viewDidAppear()中调用self.collectionView.r
我试图让 UICollectionView 快速回到靠近它的任何项目单元格的中心,但问题是,当我稍微移动它时,它会以太快的速度弹回单元格的中心,而单元格的中心看起来并不光滑,是否可以忽略或禁用滚动,除
我在使用 UICollectionViews 时遇到了 2 个问题,我以某种方式相信它在这两种情况下都与 IndexPath 相关,但是我真的不知道 Indexpath 何时被调用或它究竟做了什么以及
我是一名优秀的程序员,十分优秀!