成为FirstResponder而不隐藏键盘

发布于 2024-10-05 02:09:18 字数 414 浏览 7 评论 0原文

我有一个支持复制并使用以下代码显示编辑菜单的视图:

if ([self becomeFirstResponder]) {
    // bring up edit menu.
    UIMenuController *theMenu = [UIMenuController sharedMenuController];
    [theMenu setTargetRect:[self _textRect] inView:self];
    [theMenu setMenuVisible:YES animated:YES];
}

问题是,当调用 beginResponder 时,键盘会被隐藏。正确行为的一个很好的例子是短信应用程序。当回复框可见时双击消息,回复框将失去焦点,但键盘保持在原位。此外,当取消选择气泡时,回复框将重新获得焦点。

I have a view that supports copy and shows the edit menu using the following code:

if ([self becomeFirstResponder]) {
    // bring up edit menu.
    UIMenuController *theMenu = [UIMenuController sharedMenuController];
    [theMenu setTargetRect:[self _textRect] inView:self];
    [theMenu setMenuVisible:YES animated:YES];
}

The problem is, that when becomeFirstResponder gets called, the keyboard get's hidden. A good example of the correct behavior is in the SMS app. Double tap a message while the reply box is visible and the reply box looses focus, but the keyboard stays in place. Also, when the bubble is deselected, the reply box regains focus.

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

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

发布评论

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

评论(1

断肠人 2024-10-12 02:09:18

不幸的是,苹果可以做很多第三方应用程序无法做到的事情。

我相信如果你让视图成为第一个响应者接受键盘输入,你想要的在 iOS 3.2+ 中是可能的。您可以通过让视图类采用 来做到这一点UIKeyInput 协议

UIResponder的子类可以采用该协议来实现简单的文本输入。当该子类的实例是第一响应者时,将显示系统键盘。

该协议由您必须实现的 3 个必需方法组成。在您的情况下,您可能会将在这些方法中收到的输入应用到文本字段,并使其再次成为第一响应者。我还没有尝试过这个,但它应该有效。

Unfortunately, Apple can do a lot of things that are not available to third-party apps.

I believe what you want is possible in iOS 3.2+ if you make the view that is to become the first responder accept keyboard input. You do that by having your view class adopt the UIKeyInput protocol:

A subclass of UIResponder can adopt this protocol to implement simple text entry. When instances of this subclass are the first responder, the system keyboard is displayed.

The protocol consists of 3 required methods that you have to implement. In your case, you would probably apply the inputs you receive in these methods to your text field and make it the first responder again. I haven't tried this but it should work.

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