在UIWebView的代理方法webViewDidFinishLoad中写下如下代码
-(void)webViewDidFinishLoad:(UIWebView*)webView{
NSString*injectionJSString =@"var script = document.createElement('meta');"
"script.name = 'viewport';"
"script.content=\"width=device-width, initial-scale=1.0,maximum-scale=3.0, minimum-scale=1.0, user-scalable=yes\";"
"document.getElementsByTagName('head')[0].appendChild(script);";
[webViewstringByEvaluatingJavaScriptFromString:injectionJSString];
}
便可实现手势缩放,如果user-scalable=no,就会关闭手势缩放功能
网友评论