Programmatically zooming a UIWebView without gestures - Center Point not calculated correctly

瘦欲@ 提交于 2019-12-05 08:21:19

Have you tried implementing the zoom using JavaScript rather than the UIWebView's scrollview ?

I believe you can zoom the webview by calling:

[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.zoom = 5.0;"]; (use your ZOOM_STEP as the value)

You could also calculate the center of the browser window using JS:

posY = getScreenCenterY();
posX = getScreenCenterX();

function getScreenCenterY() {
    var y = 0;
    y = getScrollOffset()+(getInnerHeight()/2);
    return(y);
}

function getScreenCenterX() {
    return(document.body.clientWidth/2);
}

function getInnerHeight() {
    var y;
    if (self.innerHeight) // all except Explorer
    {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
    {
        y = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        y = document.body.clientHeight;
    }
    return(y);
}

function getScrollOffset() {
    var y;
    if (self.pageYOffset) // all except Explorer
    {
        y = self.pageYOffset;
    }
    else if (document.documentElement &&
document.documentElement.scrollTop) // Explorer 6 Strict
    {
        y = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        y = document.body.scrollTop;
    }
    return(y);
}

(source: http://sliceofcake.wordpress.com/2007/09/13/use-javascript-to-find-the-center-of-the-browser/)

user1278459
for (UIScrollView *scroll in [myPDFView subviews]) {
  //Set the zoom level.
  [scroll setZoomScale:2.5f animated:YES];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!