Kyle
Kyle

Reputation: 33701

How do I disable bouncing on ScrollView in Xamarin Forms for iOS?

I'm using a ScrollView in Xamarin Forms and on iOS, the scrollview bounces (often too far) when you hit the top or the bottom. My understanding is this is default iOS behavior? Is there a way I can disable this so there is no bounce on scroll?

Upvotes: 0

Views: 5091

Answers (1)

Demitrian
Demitrian

Reputation: 3230

Yes, disabling the bouncing effect is possible. But you will need to create a Custom Renderer.

In your specific case, you have to use ScrollViewRenderer as a base class for your custom renderer. Then, in your custom renderer, you can simply set Bounces to false.

An example of a Custom Renderer can be found here. Your result should look something like this:

PCL:

public class CustomScrollView : ScrollView
{
    public CustomScrollView() {}
}

iOS:

[assembly: ExportRenderer(typeof(CustomScrollView), typeof(CustomScrollViewRenderer))]
namespace Test.iOS
{
    public class CustomScrollViewRenderer : ScrollViewRenderer
    {
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
            Bounces = false;
        }
    }
}

On Android, you will need to implement a Custom Renderer as well which simply does nothing.

Upvotes: 10

Related Questions