以编程方式关注 web 视图中的表单 (WKWebView) [英] Programmatically focus on a form in a webview (WKWebView)

查看:21
本文介绍了以编程方式关注 web 视图中的表单 (WKWebView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 UIWebView 可以实现:

It's possible with UIWebView with following:

[webView setKeyboardDisplayRequiresUserAction:NO]
Call some JS function

当 webview 是 WKWebView 时,你如何做同样的事情?

How can you do the same when the webview is WKWebView instead?

相关:如何让 UIWebView 专注于表单输入并调出键盘?

推荐答案

在对 Webkit 源代码进行了几周的深入研究后,我通过 swizzling _startAssistingNode:userIsInteracting:blurPreviousNode 设法使其在 iOS 9 上运行:userObjectWKContentView 上并覆盖 userIsInteracting 值:

After digging into the Webkit sources for a couple of weeks, I've managed to get this working on iOS 9 by swizzling _startAssistingNode:userIsInteracting:blurPreviousNode:userObject on WKContentView and overriding the userIsInteracting value:

伪代码:

swizzle_intercept("WKContentView", "_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:", &hackAssist);

void hackAssist (id self, SEL _cmd, void* arg0, BOOL arg1, BOOL arg2, id arg3) {
    ((void (*)(id,SEL,void*,BOOL,BOOL,id))swizzle_interceptee(hackAssist))(self, _cmd, arg0, TRUE, arg2, arg3);
}

干杯!

这篇关于以编程方式关注 web 视图中的表单 (WKWebView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆