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......
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
Here's a little (1 method) category that will allow you to get the scale by calling [webView zoomScale]
.
UIWebView+zoom.h file
@interface UIWebView (zoom)
-(float)zoomScale;
@end
UIWebView+zoom.m file
@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 Class Reference
UIWebView's View Hierarchy (Don't rely on it though, always scan the webView
to avoid code breaking when apple makes changes to iOS
)
NOTE: This code should work but has been written in the reply box so hasn't been tested.