UIScrollView在分页时确定scrollViewDidEndDragging的滚动方向
有谁知道如何确定当用户抬起手指时滚动视图将向哪个方向移动,即当调用scrollViewDidEndDragging时?
具体来说,当滚动视图设置为分页时。
大多数时候,我可以跟踪并检查scrollViewDidScroll中的contentOffset,但是,也有一些特殊情况,即用户快速滑动屏幕。在某些情况下,左右移动将滚动到下一页,而在其他情况下,相同的图案将保留在同一页面上。
我猜这与触摸的加速度(最后几个点之间的差异)有关。
(我在iPad上使用iOS4.3)
Does anyone know how to determine which direction a scroll view will move when the user lifts their finger, i.e. when scrollViewDidEndDragging gets called?
Specifically, when the scroll view is set to paging.
Most of the time, I can just track and check the contentOffset in scrollViewDidScroll, however, there are special cases where the user flicks the screen quickly. In some cases a LEFT-RIGHT-LEFT move will scroll to the next page, and in others, the same pattern will remain on the same page.
I'm guessing it has something to do the with acceleration (difference between the last few points) of the touch.
(I'm on iOS4.3 on an iPad)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您不使用计时器,这是非常昂贵的操作。首先锁定滚动视图的方向,使其仅向上/向下和向左/向右移动[我猜这就是你想要的]。然后使用以下代码来确定...
You don't use timer, which is very expensive operation. Lock the direction of your scrollView first to move only up/down and left/right [I guess that's what you want]. And then use following code to determine...
这是我的解决方案,对我来说效果很好,希望它可以帮助
我退出旧的解决方案,因为新的解决方案看起来更光滑
Here is my solution works fine for me hope it helps
I quit the old solution as the new one seems more slick
实现以下 UIScrollViewDelegate 方法。
您可以比较当前内容偏移量和 targetContentOffset,然后获取方向。
Implement the following UIScrollViewDelegate Method.
You can compare current content offset and targetContentOffset then get the direction.
这是一个棘手的问题,iOS 5 有 回答,但这对你没有好处。
也许一个巧妙的解决方法是在
scrollViewDidEndDragging
完成后设置一个较小的时间间隔(例如 0.1 秒)的NSTimer
。然后比较内容偏移量。如果你想知道滚动视图是否真的会转到下一页,也许你可以检查内容偏移量是否超过了 1/2。您可以阅读
scrollViewDidScroll:
并进行一些数学计算以确定其是否超过 1/2 方式。This is a tricky one, iOS 5 has the answer, but that no good for you.
Perhaps a hacky workaround is to set a
NSTimer
for a small time interval (say 0.1 seconds) afterscrollViewDidEndDragging
finished. Then compare the content offsets.If you want to know if the scroll view will actually go to the next page, perhaps you could check if the content offset has gone more than 1/2 way. You could read the content offset on
scrollViewDidScroll:
and do a bit of maths to determine if its more than 1/2 way.另外还有索林反应。
她的解决方案工作正常,但如果您使用分页并且处于滚动内容大小的末尾,您将必须测试我们是否真的滚动到下一个“页面”:
In addition to saurin response.
Her solution work fine but if you are using pagination and you are in the end of scroll content size you will have to test if we really have a scroll to the next 'page' or not: