简体   繁体   English

Xamarin iOS Webview缩放不起作用

[英]Xamarin iOS webview Zoom is not working

When I add DraggingStarted or any other ScrollView events to webview, then Zooming got disabled. 当我将DraggingStarted或任何其他ScrollView事件添加到Webview时,Zooming被禁用。

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

//Once added following line zoom is stopped //停止行缩放后添加的内容

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

I have tried following but no luck 我试过跟随但没有运气

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

Did you tried to set a delegate to the ScrollView instead of using the events? 您是否尝试将委托设置为ScrollView而不是使用事件? Something like this: 像这样:

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

webview.ScrollView.Delegate = new ScrollViewDelegate();

EDIT: Here is the complete code that I used for the test and it worked me: 编辑:这是我用于测试的完整代码,它对我有用:

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

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

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