2

Setup: I'm using Xamarin (and Xamarin.Forms) developing an app with an embedded browser.

My issue: I have a WebView and I'm trying to detect when a user is scrolling, and whether it is Up or Down.

So far, I have created a Custom WebViewRenderer for the iOS-project. But how does one subscribe to scrolling events? Googling makes me believe that overriding the WebViewRenderer's

OnElementChanged(VisualElementChangedEventArgs e)

should be the right way, but I can't seem to find any documentation/leads on how to go further. Does anyone know, or can point me in the right direction?

1

1 Answer 1

3

Both MKWebView and UIWebView contain a UIScrollView that you can assign a UIScrollViewDelegate to its ScrollView.Delegate property and track scrollViewDidScroll to determine the panning direction:

public class UIScrollViewDelegate : NSObject, IUIScrollViewDelegate
{
    [Export("scrollViewDidScroll:")]
    public void Scrolled(UIScrollView scrollView)
    {
        var translation = scrollView.PanGestureRecognizer.TranslationInView(scrollView.Superview);
        Console.WriteLine($"Scrolling {(translation.Y > 0 ? "Down" : "Up")}");
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.