开发者

iPad Zoom Scale Detection

I'm trying to find a way to detect how zoomed in someone is on a web app so that when they click to pull up a menu, the menu stays the same size regardless of the zoom. To do that, I need to be able to scale the size of the menu appropriately relative to the zoom. Is there a way to do this开发者_运维知识库?


First, all UIWebView has as a UIScrollView subview. So, in order to get it you could do the following:

for (UIView * v in [_webView subviews]) {

    if ([v isKindOfClass:[UIScrollView class]]) {
        UIScrollView * s = (UIScrollView*)v;
        // use the scrollview
    }

}

After that you can use the UIScrollView to find out the zoom scale. Unfortunately, the property zoomScale doesn't tell us, in this case, what we want, but we can use the contentSize and the frame of the scrollView, as the following:

CGFloat zoomScale = s.contentSize.width / s.frame.size.width;

After that, I suppose you want to tell your javascript code about this zoomScale. You could use the following code:

[_webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"yourJSZoomScaleVar = %f;", zoomScale]];

Hope it helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜