如何解决如何根据tableView滚动的速度控制是否会发生功能
如果用户以任何速度向下滚动,或者用户以快速向上滚动(或到达视图控制器的顶部),我希望发生一个动作。我正在使用下面的代码来感测任何移动并实现“向上移动”和“向下移动”注释所在的功能,但是我想限制向上移动仅在快速滚动或用户到达时才发生tableView的顶部。我该怎么做?
const photoData = await camera.takePictureAsync({
base64: true,exif: false,});
解决方法
我想您可以存储调用scrollViewWillBeginDragging
的时间,然后在scrollViewDidScroll
中测量相对于一定时间的时间差
var timeScrollingBegan: Date?
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
// ...
timeScrollingBegan = Date()
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if self.lastContentOffset < scrollView.contentOffset.y {
// Calculate time difference in milliseconds
let timeDifference = Date().timeIntervalSince(timeScrollingBegan) * 1000
let movementDifference = scrollView.contentOffset.y - lastContentOffset
// If the movement difference is past a certain threshold
// in a certain amount of time,then it is too fast. It will
// take a bit of trial and error to determine the correct threshold
}
// ...
}
// You can probably use scrollViewDidEndDecelerating here instead
func scrollViewDidEndDragging(_ scrollView: UIScrollView,willDecelerate decelerate: Bool) {
timeScrollingBegan = nil
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。