- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 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/
为什么这不起作用?我在 targetContentOffset->y = -50.0f; 设置了一个断点,并且它被击中,不知道为什么它没有任何效果。 是的寻呼 = 否。 - (void)scrollV
我需要在纵向模式下保持 UICollectionViewCell 居中对齐。 最终结果应该是这样的: animation 我正在使用此代码来执行此操作: override public func ta
我正在编写一个自定义的 UICollectionViewFlowLayout,它覆盖了 targetContentOffset(forProposedContentOffset:),以便在用户缩放时提
我希望 UIScrollView 始终滚动回特定点。我通过写作实现了它: - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
我使用以下代码在我的应用中实现了大标题: if #available(iOS 11.0, *) { navigationController?.navigationBar.pr
documentation声明它是 points(每秒,我假设)?但是,我得到的值在 (.5, 3.5) 范围内。然后 ScrollView 在停止之前移动了数百个点。实际初速度应该相差几个数量级。
我正在为 targetContentOffset 设置一个新值在 scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)在 UIT
我有一个实现分页的 Collection View ,这就是为什么我在自定义 UICollectionViewFlowLayout 中覆盖 targetContentOffset 来处理它。当通过用户
我在一个 View Controller 上有两个 UITableViews( View Controller 是他们的代表)。其中之一将取决于 scrollViewWillEndDragging:w
在我的 UIViewController 中,我有一个 UICollectionView。委托(delegate)设置正确。它工作正常。 isPagingEnabled 设置为 true。但是现在我想
我正在尝试实现一个自定义标签栏,它是可滚动的并且在每个标签栏项目上都有分页。为此,我正在使用代理 scrollViewWillEndDragging:withVelocity:targetConten
如何用 Swift 编写此代码? 更新:发布了我试图转换的方法,最初发布了一个不同的方法,这不是我试图隐藏的方法 这适用于 Objective C,但不适用于 Swift。当我尝试将 ceilf 和
我希望我的垂直 UIScrollView 仅在用户向上滚动时停在最大内容偏移处,或者在用户向下滚动时停在最小内容偏移处。 我正在使用以下两个函数 func targetContentOffset(fo
我是一名优秀的程序员,十分优秀!