在 wkwebview 上禁用放大/缩小
Posted
技术标签:
【中文标题】在 wkwebview 上禁用放大/缩小【英文标题】:Disable zoom in/out on wkwebview 【发布时间】:2016-06-30 03:32:43 【问题描述】:我想禁用包含 iframe 的 wkwebview 的放大和缩小 我试过了
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" >
在我的网站上,但它不起作用。有什么建议吗?
【问题讨论】:
这个问题已经回答了。看看***.com/a/31943976/7220486 【参考方案1】:你可以试试这个。从这个要点https://gist.github.com/paulofierro/66aea963303df735aa00
// Remember to @import WebKit at the top of the class
// javascript that disables pinch-to-zoom by inserting the html viewport meta tag into <head>
NSString *source = @"var meta = document.createElement('meta'); \
meta.name = 'viewport'; \
meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'; \
var head = document.getElementsByTagName('head')[0];\
head.appendChild(meta);";
WKUserScript *script = [[WKUserScript alloc] initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
// Create the user content controller and add the script to it
WKUserContentController *userContentController = [WKUserContentController new];
[userContentController addUserScript:script];
// Create the configuration with the user content controller
WKWebViewConfiguration *configuration = [WKWebViewConfiguration new];
configuration.userContentController = userContentController;
// Create the web view with the configuration
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
webView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:webView];
// Add the constraints
NSDictionary *views = NSDictionaryOfVariableBindings(webView);
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[webView]|" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[webView]|" options:0 metrics:nil views:views]];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://apple.com"]]];
【讨论】:
以上是关于在 wkwebview 上禁用放大/缩小的主要内容,如果未能解决你的问题,请参考以下文章