gpt4 book ai didi

ios - Hybrid Webview IOS停止缩放

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:11:08 25 4
gpt4 key购买 nike

我正在使用 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 head 中添加以下标记来禁用那里的缩放:

<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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com