【问题标题】:Stop the IOS bouncing in Xamarin.Forms停止 IOS 在 Xamarin.Forms 中弹跳
【发布时间】:2019-02-07 19:18:53
【问题描述】:

我正在 Xamarin.Form 中创建应用程序,我是 Xamarin 的新手。在 IOS 中,应用程序在顶部滚动时弹跳。有没有办法阻止滚动弹跳?

我尝试运行 CSS 文件但没有成功。

【问题讨论】:

    标签: c# ios xaml xamarin.forms


    【解决方案1】:

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

    【讨论】:

    • 是的,它给了我一个开始,我得到了它的工作。谢了!
    【解决方案2】:

    原因:在 Xamarin.forms for iOS 中有一些 UITableView 的属性(表单中的列表视图)。

    @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是行不通的。你应该将bounces设置为false。

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

    【讨论】:

    • "因此,仅将 AlwaysBounceVertical 设置为 false 将不起作用。"我在发布此答案之前对其进行了测试。它工作正常:)
    猜你喜欢
    • 2013-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多