How to determine when the scrollviewer has ended scrolling?

纵然是瞬间 提交于 2019-12-12 19:17:26

问题


I need to adjust the scrollviewer to some point after the users has completed scrolling. For that i need to get to listen to when the scrolling has ended.

iOS's UIScrollView has some similar methods

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView that is called when the scrollview

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate

I tried ViewChanging and ViewChanged, But problem with handling both events simultaneously is that they occur one after another. Like following:

view changing

view changed

view changing

view changed

..

..

instead of -

view changing

view changing

view changing

view changing

view changed

Is there any way i can get the notification for when the scrollviewer has done scrolling or done scrolling-through-dragging?

Please help.


回答1:


What You could do is :

  • 1.Capture MouseWheel event.
  • 2.Fire up a thread in the event handler of MouseWheel, that would count time to raise a custom event of yours like FinishedScrolling
  • 3.If a MouseWheel event gets raised before the timer finishes, that means that the scrolling isn't done and you should terminate your timer-thread and start it again.

How's that ? It shouldn't take up too much code and if you're using MVVM you could use an Attached Behaviour.



来源:https://stackoverflow.com/questions/21234210/how-to-determine-when-the-scrollviewer-has-ended-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!