简体   繁体   中英

Xamarin iOS webview Zoom is not working

When I add DraggingStarted or any other ScrollView events to webview, then Zooming got disabled.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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