简体   繁体   English

Xamarin Forms-附加scrollview。滚动到一个函数

[英]Xamarin Forms - attaching scrollview.Scrolled to a function

When I attach a scrollview to a function like this 当我将滚动视图附加到这样的功能时

textScroll.Scrolled += (sender, e) => { onScrolled(); };

Each time I scroll up or down, OnScrolled() is called multiple times. 每次我向上或向下滚动时,都会多次调用OnScrolled()。 I know I can get the size of the content and compare it to the ScrollY value, obviously the ScrollY value changes each time, but as far as I can see I won't know when the last call happens (per user scroll). 我知道我可以获取内容的大小并将其与ScrollY值进行比较,显然ScrollY值每次都会更改,但是据我所知,我不知道最后一次调用发生的时间(按用户滚动)。

I only want to call this once per scroll, failing that call it each time as is happening now, but only act when I know I'm on the last call. 我只希望每个滚动调用一次,但每次失败都不会像现在这样调用,但是只有在我知道上次通话时才采取行动。

Is this possible? 这可能吗?

thanks 谢谢

It is possible, but with a custom renderer for each platform. 可以,但是每个平台都有一个自定义渲染器。

On iOS: you will want to implement delegates for DecelerationEnded and WillEndDragging . iOS上:您将要实现DecelerationEndedWillEndDragging委托。 The reason for also implementing DecelerationEnded is to allow for a fling by the user and waiting for the velocity to come to 0. 还实现DecelerationEnded的原因是允许用户猛扑并等待速度变为0。

On Android it is a bit more complicated. Android上,它有点复杂。 Here is a native Android SO post I followed and translated into c# in a renderer. 这是我关注的原生Android SO帖子,并在渲染器中翻译为c#。 Works pretty well for me. 对我来说效果很好。 Android: Detect when ScrollView stops scrolling Android:检测ScrollView何时停止滚动

After having both implemented, you can call to your Xamarin.Forms view in order to notify that the view has Stopped scrolling (ie final call) 都实现后,可以调用Xamarin.Forms视图,以通知该视图已停止滚动(即最终调用)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM