繁体   English   中英

停止Xamarin.Forms中的IOS弹跳

[英]Stop the IOS bouncing in Xamarin.Forms

我在Xamarin.Form中制作应用程序,而我在Xamarin中是新手。 在IOS中,当滚动到顶部时,应用程序会反弹。 无论如何,有没有停止滚动弹跳?

我尝试运行CSS文件,但无法正常工作。

在iOS上有一个专用的属性。 这是AlwaysBounceVertical 也有一些相关的属性。

但是,Forms不直接支持设置这些属性,因此您需要创建一个自定义渲染器或相等的渲染器。 看看这个:

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;
            }
        }
    }
}

原因:在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

所以,只设置AlwaysBounceVertical为false将不会work.You应该将bounces为假。

解决方案:正如@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