成为FirstResponder而不隐藏键盘
我有一个支持复制并使用以下代码显示编辑菜单的视图:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,苹果可以做很多第三方应用程序无法做到的事情。
我相信如果你让视图成为第一个响应者接受键盘输入,你想要的在 iOS 3.2+ 中是可能的。您可以通过让视图类采用 来做到这一点
UIKeyInput
协议:该协议由您必须实现的 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: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.