- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何让 UIScrollView 在 View 末尾停止拖动,并将其捕捉到正确的位置?我尝试使用以下代码,但是虽然它正确减速并捕捉到 View 顶部的完美位置,但它不允许我向下滚动:
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
let layout = self.collectionView?.collectionViewLayout as! UICollectionViewFlowLayout
let itemHeightIncludingSpacing = self.view.frame.height + layout.minimumInteritemSpacing
var offset = targetContentOffset.memory
let index = (offset.x + scrollView.contentInset.bottom) / itemHeightIncludingSpacing
let roundedIndex = round(index)
offset = CGPoint(x: roundedIndex * itemHeightIncludingSpacing - scrollView.contentInset.bottom, y: -scrollView.contentInset.top)
targetContentOffset.memory = offset
}
这是我的 ScrollView 的顶部:
这是底部,它不在你所看到的应该的位置。它应该与底部偏移值齐平,就像顶部一样:
如何让滚动条像顶部一样停止齐平?
最佳答案
您是否制作了具有该方法的 UIScrollView 扩展?它不存在,但 scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) 存在。如果这是您在扩展中的自定义方法,请确保在代码中的某个位置调用它(如我提到的委托(delegate)方法)。另外,重置参数对 ScrollView 没有任何作用。我建议采用不同的方法。
我也不知道你在这里问什么。您是否不希望内容在弹回原位之前被拉过屏幕边缘?如果是这样,则不需要该方法。只需将 self.myScrollView.bounces = false 添加到 viewDidLoad()
编辑:好的,试试这个
func collectionView(collectionView: UICollectionView, 布局 collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex 部分: Int) -> UIEdgeInsets {
返回 UIEdgeInsetsMake(0, 0, 0, 0)
}
关于ios - 正确的scrollViewWillEndDragging代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32082820/
我在 TabelViewCell 中有 CollectionView,我正在尝试为 CollectionView 的单元格进行分页和居中。但是当我使用方法时 func scrollViewWillEn
我有一个 View 覆盖在 UITableView 的顶部。但是当用户在顶部 View 上拖动时,我需要触发 UITableView 事件的滚动事件。 我在 View 上添加了 UIPanGestur
我找遍了所有地方,但找不到答案。所以,开始吧。我创建了一个长 ScrollView ,里面有 568 像素(全屏) View 。当用户向下滚动时,我希望 ScrollView 捕捉到特定位置。这是我的
我正在为我的 UICollectionView 创建自定义分页。我希望底部的一些单元格卡在屏幕边缘,但是,通过常规分页,滚动到下一页意味着如果页面底部的一半单元格显示,它只会显示另一半在下一页。我想让
documentation声明它是 points(每秒,我假设)?但是,我得到的值在 (.5, 3.5) 范围内。然后 ScrollView 在停止之前移动了数百个点。实际初速度应该相差几个数量级。
这是我的覆盖代码 - 它只是计算捕捉到的位置: - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(C
我正在为 targetContentOffset 设置一个新值在 scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)在 UIT
我希望我的 UIScrollView 以特定的增量值自然地滑动到结尾,对应于水平滚动 UIScrollView 的每 50 个宽度点。为此,我定制的 scrollViewWillEndDragging
我正在尝试在 iOS 5 中使用新的 scrollViewWillEndDragging:withVelocity:targetContentOffset: UIScrollView 委托(deleg
我在一个 View Controller 上有两个 UITableViews( View Controller 是他们的代表)。其中之一将取决于 scrollViewWillEndDragging:w
我在同一个 View Controller 上使用 UITableView 和 UICollectionView。 我想改变 UICollectionView 的滚动方式,所以我在扩展中添加了一个 s
我正在尝试使用 scrollViewWillEndDragging: 方法来滚动我自己的分页 UICollectionView,在两侧都有预览,类似于 App Store 应用程序。但是,如果我停止无
我正在尝试实现一个自定义标签栏,它是可滚动的并且在每个标签栏项目上都有分页。为此,我正在使用代理 scrollViewWillEndDragging:withVelocity:targetConten
如何用 Swift 编写此代码? 更新:发布了我试图转换的方法,最初发布了一个不同的方法,这不是我试图隐藏的方法 这适用于 Objective C,但不适用于 Swift。当我尝试将 ceilf 和
我希望我的垂直 UIScrollView 仅在用户向上滚动时停在最大内容偏移处,或者在用户向下滚动时停在最小内容偏移处。 我正在使用以下两个函数 func targetContentOffset(fo
我是一名优秀的程序员,十分优秀!