我可以禁止键盘在 UIWebView 中显示吗?

发布于 2024-12-10 17:39:29 字数 39 浏览 0 评论 0原文

当在 UIWebView 中选择网页元素时是否可以禁用键盘显示?

Is it possible to disable the keyboard from showing when a webpage element is selected inside a UIWebView?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难以启齿的温柔 2024-12-17 17:39:29

注册键盘通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

然后您可以通过将以下代码放入keyboardWillShow中来阻止它显示:

UITextField *dummyTextField = etc. 
//Basically, create a dummy uitextfield that you never show. 
//I can't remember all the syntax :)


[dummyTextField becomeFirstResponder];
[dummyTextField resignFirstResponder];
//Keyboard should be gone. Hoorah!

不确定这是否可以正常工作100%。如果键盘开始动画然后再次隐藏自身,您可以使用

[UIView enableAnimations:NO];

如果键盘在显示时不喜欢被放弃,那么您可以尝试将虚拟 textField 的 inputView 属性更改为某个虚拟 UIView 。

希望这能让你有所收获!

Register for a keyboard notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

And then you can stop it from showing by placing the following code in keyboardWillShow :

UITextField *dummyTextField = etc. 
//Basically, create a dummy uitextfield that you never show. 
//I can't remember all the syntax :)


[dummyTextField becomeFirstResponder];
[dummyTextField resignFirstResponder];
//Keyboard should be gone. Hoorah!

Not sure 100% if this will work without flaws. If the keyboard starts to animate then hides itself again, you could use

[UIView enableAnimations:NO];

If the keyboard doesn't like being resigned while it's showing then you could try changing the inputView property of the dummy textField to some dummy UIView instead.

Hopefully this should get you somewhere!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文