【发布时间】:2017-06-15 09:01:33
【问题描述】:
我正在为scrollViewWillEndDragging(_:withVelocity:targetContentOffset:) 中的targetContentOffset 设置一个新值,以在UITableView 中创建自定义分页解决方案。当为targetContentOffset 设置与速度指向的滚动方向相同的坐标时,它可以按预期工作。
但是,当以与速度相反的方向“向后”捕捉时,它会立即“向后捕捉”而没有动画。这看起来很糟糕。关于如何解决这个问题的任何想法。
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
// a lot of caluculations to detemine where to "snap scroll" to
if shouldSnapScrollUpFromSpeed || shouldSnapScrollUpFromDistance {
targetContentOffset.pointee.y = -scrollView.frame.height
} else if shouldSnapScrollDownFromSpeed || shouldSnapScrollDownFromDistance {
targetContentOffset.pointee.y = -detailViewHeaderHeight
}
}
我可以潜在地计算出这个“错误”何时会出现,并可能使用另一种“快速滚动”方式。有关如何执行此操作或正常使用targetContentOffset.pointee.y 解决此问题的任何建议?
【问题讨论】:
-
你的问题本身的标题拯救了我的一天。非常感谢你。我无法让自己在什么情况下动画会中断。就我而言,我将通过始终自动滚动到“正确”方向来修复它。再次感谢!
标签: uitableview cocoa-touch uiscrollview uiscrollviewdelegate