Xamarin iOS webview 缩放不工作

Xamarin iOS webview Zoom is not working

当我将 DraggingStarted 或任何其他 ScrollView 事件添加到 webview 时,缩放被禁用。

string urlAddress = "http://google.com";
NSUrl url = NSUrl.FromString(urlAddress);
//URL Requst Object
NSUrlRequest requestObj = NSUrlRequest.FromUrl(url);
webview.LoadRequest (requestObj);

//添加后停止缩放

webview.ScrollView.DraggingStarted += (object sender, EventArgs e) => {};

我试过跟随但没有成功

webview.ScrollView.ViewForZoomingInScrollView = (scrollView) => {
    return webview;
};

您是否尝试过为 ScrollView 设置委托而不是使用事件?像这样:

public class ScrollViewDelegate : UIScrollViewDelegate
{
    public override void DraggingStarted(UIScrollView scrollView)
    {
        Console.WriteLine("DraggingStarted");
    }
}

webview.ScrollView.Delegate = new ScrollViewDelegate();

编辑: 这是我用于测试的完整代码,它对我有用:

public class IPadViewController1 : UIViewController
{
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        UIWebView webview = new UIWebView(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height));
        webview.ScrollView.Delegate = new ScrollViewDelegate();
        webview.ScalesPageToFit = true;
        View.AddSubview(webview);

        string urlAddress = "http://google.com";
        NSUrl url = NSUrl.FromString(urlAddress);
        //URL Requst Object
        NSUrlRequest requestObj = NSUrlRequest.FromUrl(url);
        webview.LoadRequest(requestObj);
    }
}