【问题标题】:How to Disable Elastic Bounce in Xamarin iOS 13.2 application?如何在 Xamarin iOS 13.2 应用程序中禁用弹性反弹?
【发布时间】:2020-07-12 04:32:45
【问题描述】:

我有一个在滚动时反弹的 web 视图。以前我通过实现自定义渲染器禁用了它。

    protected override void OnElementChanged(ElementChangedEventArgs<FormsWebView> e)
    {
        base.OnElementChanged(e);
        if(Control != null)
        {
            Control.ScrollView.Bounces = false;

        }
    } 

但更新到 13.2 后,上述修复不起作用。

谁能提出解决此问题的最佳方法?

【问题讨论】:

    标签: c# ios xamarin xamarin.forms cross-platform


    【解决方案1】:

    如果你也使用 UIWebView 来实现它,你可以改为使用 WKWebView 。因为 Apple 从 iOS 13 弃用了 UIWebView

    [assembly: ExportRenderer(typeof(HybridWebView), typeof(HybridWebViewRenderer))]
    namespace CustomRenderer.iOS
    {
        public class HybridWebViewRenderer : WkWebViewRenderer
        {
    
            public HybridWebViewRenderer() : this(new WKWebViewConfiguration())
            {
            }
    
            public HybridWebViewRenderer(WKWebViewConfiguration config) : base(config)
            {
    
            }
    
            protected override void OnElementChanged(VisualElementChangedEventArgs e)
            {
                base.OnElementChanged(e);
    
                ScrollView.Bounces = false;
            }
    
           protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    ((HybridWebView)Element).Cleanup();
                }
                base.Dispose(disposing);
            }
        }
    }
    

    它在我的本地站点中的工作方式如下:

    【讨论】:

    • 我厌倦了你的实现,但我仍然在 web 应用程序的其他可滚动元素中具有反弹效果。
    • @RashedulAlam 你能在这里分享一个示例项目链接,我会检查一下。或者您可以更新有问题的完整渲染器代码。我想你可以检查一下我的渲染器代码,它可能与你的不同。
    • 你可以找到我的完整实现here
    • @RashedulAlam 从共享代码来看,没有问题。你有尝试过其他版本的 iOS 吗?因为我的设备和模拟器是13.4的。稍后我会分享我的工作示例项目。
    • @RashedulAlam 这是我的示例项目链接:dropbox.com/s/zffm87twobsdtd7/AppWKWebViewSample.rar?dl=0。它适用于 iOS 13.4。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    • 2014-07-14
    • 2012-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多