在UIWebView中检测Zoomscale [英] Detect Zoomscale in UIWebView

查看:76
本文介绍了在UIWebView中检测Zoomscale的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我想检测UIWebView的缩放比例,我已经尝试过搜索它,但是没有给出正确的答案.欢迎您提供帮助...

My problem is that i want to detect the zoom scale of an UIWebView, i have tried searching it but did not come out with a proper answer.Any help is appreciated......

推荐答案

虽然UIWebView没有zoomScale属性,但是UIScrollView有! 因此,我们只需扫描它的subView's中的scrollView内容,然后以这种方式获取它即可.

Well although the UIWebView doesn't have a zoomScale property, UIScrollView does! So we just scan it's subView's for the scrollView everything sits in and get it that way.

这里有一个小方法(1种方法),可以通过调用[webView zoomScale]来获取比例.

Here's a little (1 method) category that will allow you to get the scale by calling [webView zoomScale].

UIWebView + zoom.h文件

@interface UIWebView (zoom)
-(float)zoomScale;
@end

UIWebView + zoom.m文件

@implementation UIWebView (zoom)

-(float)zoomScale{
    UIScrollView *webViewContentView;
    for (UIView *checkView in [self subviews] ) {
        if ([checkView isKindOfClass:[UIScrollView class]]) {
            webViewContentView = (UIScrollView*)checkView;
            break;
        }
    }
    return webViewContentView.zoomScale;
}

@end

UIScrollView类参考

UIWebView的视图层次结构 (尽管不要依赖它,请始终扫描webView以避免在Apple对iOS进行更改时代码被破坏)

UIWebView's View Hierarchy (Don't rely on it though, always scan the webView to avoid code breaking when apple makes changes to iOS)

注意:此代码应该可以使用,但是已在回复框中编写了代码,因此未经测试.

这篇关于在UIWebView中检测Zoomscale的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆