简体   繁体   English

停止Xamarin.Forms中的IOS弹跳

[英]Stop the IOS bouncing in Xamarin.Forms

Im making an application in Xamarin.Form and i am new in Xamarin. 我在Xamarin.Form中制作应用程序,而我在Xamarin中是新手。 In IOS the application bounce when scroll in the top. 在IOS中,当滚动到顶部时,应用程序会反弹。 Is there anyway to stop the scroll bouncing? 无论如何,有没有停止滚动弹跳?

I try running a CSS file and did not work. 我尝试运行CSS文件,但无法正常工作。

There is a dedicated property for this on iOS. 在iOS上有一个专用的属性。 This is AlwaysBounceVertical . 这是AlwaysBounceVertical There are also a few related properties to this. 也有一些相关的属性。

Setting these properties isn't supported directly in Forms though, so you need to create a custom renderer or equal. 但是,Forms不直接支持设置这些属性,因此您需要创建一个自定义渲染器或相等的渲染器。 Have a look at this one: 看看这个:

using NoBounceiOS.iOS;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(ListView), typeof(NoBounceRenderer))]
namespace NoBounceiOS.iOS
{
    public class NoBounceRenderer : ListViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.AlwaysBounceVertical = false;
            }
        }
    }
}

Cause: in Xamarin.forms for iOS there are some property of UITableView(listview in forms). 原因:在iOS的Xamarin.forms中,有UITableView(表单中的listview)的某些属性。

@property(nonatomic)  BOOL  bounces;                  // default YES. if YES, bounces past edge of content and back again

@property(nonatomic)  BOOL  alwaysBounceVertical;     // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically

@property(nonatomic)  BOOL  alwaysBounceHorizontal;   // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag horizontally

So ,only set AlwaysBounceVertical as false will not work.You should set the bounces as false. 所以,只设置AlwaysBounceVertical为false将不会work.You应该将bounces为假。

Solution: As @Gerald Versluis said you can use CustomRenderer. 解决方案:正如@Gerald Versluis所说,您可以使用CustomRenderer。

public class MyListViewRenderer:ListViewRenderer
{
    public MyListViewRenderer()
    {

    }

    protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
    {
        base.OnElementChanged(e);

        if(Control!=null)
        {
            Control.Bounces = false;
        }


    }
}

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

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