gpt4 book ai didi

uitableview - 将 scrollViewWillEndDragging 中的 targetContentOffset 更新为错误方向的值不会产生动画

转载 作者:行者123 更新时间:2023-12-03 17:37:43 24 4
gpt4 key购买 nike

我正在为 targetContentOffset 设置一个新值在 scrollViewWillEndDragging(_:withVelocity: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 解决它的任何建议像平常一样?

最佳答案

我找到了一个不错的解决方案(或解决方法)。如果有人有更好的解决方案,请告诉我。

我刚刚检测到不想要的“非动画快速滚动”何时出现,然后没有将新值设置为 targetContentOffset.pointee.y我将其设置为当前偏移值(停止它)并使用 scrollViews setContentOffset(_:animated:) 设置所需的偏移目标值反而

if willSnapScrollBackWithoutAnimation {
targetContentOffset.pointee.y = -scrollView.frame.height+yOffset //Stop the scrolling
shouldSetTargetYOffsetDirectly = false
}

if let newTargetYOffset = newTargetYOffset {
if shouldSetTargetYOffsetDirectly {
targetContentOffset.pointee.y = newTargetYOffset
} else {
var newContentOffset = scrollView.contentOffset
newContentOffset.y = newTargetYOffset
scrollView.setContentOffset(newContentOffset, animated: true)
}
}

关于uitableview - 将 scrollViewWillEndDragging 中的 targetContentOffset 更新为错误方向的值不会产生动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44563230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com