在UIWebView中检测Zoomscale [英] Detect Zoomscale in UIWebView
问题描述
我的问题是我想检测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
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屋!