I am setting a new value to targetContentOffset
in scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)
to create a custom paging solution in a UITableView
. It works as expected when setting a coordinate for targetContentOffset
that is in the same scroll direction as the velocity is pointing.
However, when snapping "backward" in the opposite direction of the velocity it does immediatelly "snap back" without animation. This looks quite bad. Any thoughts on how to solve this.
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
}
}
I could potentionally calculate when this "bug" will appear and perhaps use another way of "snap scrolling". Any suggestions on how to do this or solve it using targetContentOffset.pointee.y
as normal?