关闭 IPAD 上的键盘

发布于 2024-09-11 06:15:22 字数 88 浏览 0 评论 0 原文

Iphone 上 UITextField 的 ResignFirstResponder 似乎不适用于 Ipad。 如何以编程方式关闭键盘?

谢谢,

The ResignFirstResponder for an UITextField on the Iphone semms to not working for the Ipad.
How can I dismiss my keyboard programmatically?

Thanks,

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

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

发布评论

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

评论(3

柠檬心 2024-09-18 06:15:22

在 iOS 4.3 中,Apple 引入了上述方法 disablesAutomaticKeyboardDismissal。它为 UIModalPresentationFormSheet 返回 YES,防止键盘消失。

重写此方法是可行的,但是如果您在 UINavigationController 中呈现视图控制器,则必须子类化 UINavigationController 并重写那里的方法。

我已经确认这确实适用于 iOS 6。只需确保注意 UINavigationController 子句即可。

In iOS 4.3, Apple introduced the above mentioned method, disablesAutomaticKeyboardDismissal. It returns YES for UIModalPresentationFormSheet, preventing the keyboard from dismissing.

Overriding this method works, but if you present your view controller inside a UINavigationController, you must subclass UINavigationController and override the method there.

I've confirmed that this does indeed work on iOS 6. Just make sure to pay attention to the UINavigationController clause.

薯片软お妹 2024-09-18 06:15:22

现在我们可以

- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}

Now we can

- (BOOL)disablesAutomaticKeyboardDismissal {
    return NO;
}
习惯那些不曾习惯的习惯 2024-09-18 06:15:22

更新此答案不再准确。请参阅正确答案

如果您的 UITextField 位于模式页面工作表视图 (UIModalPresentationFormSheet) 中,则(当前)无法强制设备关闭键盘 此开发论坛帖子来自一位苹果工程师。

UPDATE This answer is no longer accurate. See the correct answer.

If your UITextField is in a modal page sheet view (UIModalPresentationFormSheet), then there is (currently) no way to force the device to dismiss the keyboard this devforums post from an apple engineer.

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