我正在使用 Xamarin Forms 构建一个应用程序,在此我实现了一个混合 webview。在 IOS 中,混合 Web View 具有缩放功能,我需要禁用它。
这是我迄今为止尝试过的:-
public class ActivityHybridWebViewRenderer : ViewRenderer<ActivityHybridWebView, WKWebView>, IWKScriptMessageHandler
{
const string JavaScriptFunction = "function invokeCSharpAction(data){window.webkit.messageHandlers.invokeAction.postMessage(data);}";
WKUserContentController userController;
protected override void OnElementChanged(ElementChangedEventArgs<ActivityHybridWebView> e)
{
base.OnElementChanged(e);
if (Control == null)
{
userController = new WKUserContentController();
var script = new WKUserScript(new NSString(JavaScriptFunction), WKUserScriptInjectionTime.AtDocumentEnd, false);
userController.AddUserScript(script);
userController.AddScriptMessageHandler(this, "invokeAction");
var config = new WKWebViewConfiguration { UserContentController = userController };
var webView = new WKWebView(Frame, config);
webView.ScrollView.MultipleTouchEnabled = false;
webView.ScrollView.Bounces = false;
SetNativeControl(webView);
}
if (e.OldElement != null)
{
Control.ScrollView.MultipleTouchEnabled = false;
Control.ScrollView.Bounces = false;
userController.RemoveAllUserScripts();
userController.RemoveScriptMessageHandler("invokeAction");
var hybridWebView = e.OldElement as ActivityHybridWebView;
hybridWebView.Cleanup();
}
if (e.NewElement != null)
{
string localpath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string url = Path.Combine(localpath, Element.Uri);
Control.LoadFileUrl(new NSUrl("file://" + url), new NSUrl("file://" + Path.GetDirectoryName(url)));
Task.Run(() =>
{
Task.WaitAny(Task.Delay(2000));
InjectJS(JavaScriptFunction);
CallJS();
});
}
}
这两行好像没有效果-
Control.ScrollView.MultipleTouchEnabled = false;
Control.ScrollView.Bounces = false;
webView.ScrollView.MultipleTouchEnabled = false;
webView.MultipleTouchEnabled = false;
您可以更改网站代码吗?如果是,您可以通过在 html 头中添加以下标签来禁用缩放:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
关于ios - Hybrid Webview IOS 停止缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43510734/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |