取消键盘后使inputAccessoryView可见 [英] Leaving inputAccessoryView visible after keyboard is dismissed

查看:213
本文介绍了取消键盘后使inputAccessoryView可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是在iPad上的Safari中创建类似于在页面上查找"搜索功能的内容.

What I'm trying to do is to create something similar to the "find on page" search function in Safari on iPad.

我正在使用带有某些项目的UIToolbar,并将其设置为UITextField上的inputAccessoryView并将其连接到键盘.就像魅力一样工作,但我无法弄清一件事.在Safari中,当您搜索某些内容时,键盘会消失,但工具栏仍保留在屏幕底部.

I'm using a UIToolbar with some items in it and attached it to the keyboard by setting it as an inputAccessoryView on the UITextField. Works like a charm, but there is one thing I can't figure out. In Safari, when you search for something, the keyboard disappears but the tool bar remains on the bottom of the screen.

有人对如何做到这一点有所了解吗?我能想到的唯一解决方案是响应键盘关闭事件,然后拉出UIToolBar并创建一个自定义动画,将其移动到屏幕底部.但这是hacky.我正在寻找更优雅的解决方案.可以让我决定在键盘被关闭时如何处理输入附件视图.

Does anyone have a clue on how to accomplish this? The only solution I can think of is to respond to a keyboard dismissed event and then pull out the UIToolBar and create a custom animation that moves it to the bottom of the screen. But this is hacky. I am looking for a more elegant solution. Something that can make me decide what to do with the input accessory view when the keyboard gets dismissed.

推荐答案

它是这样完成的:

将UIToolbar分配给视图控制器中的属性:

Assign your UIToolbar to a property in your view controller:

@property (strong, nonatomic) UIToolbar *inputAccessoryToolbar;

在顶视图控制器中,添加以下方法:

In your top view controller, add these methods:

- (BOOL)canBecomeFirstResponder{

    return YES;

}

- (UIView *)inputAccessoryView{

    return self.inputAccessoryToolbar;

}

然后(可选,因为通常不需要这样做),每当键盘被隐藏时,只需调用:

And then (optionally, as it usually shouldn't be necessary), whenever the keyboard gets hidden, just call:

[self becomeFirstResponder];

这样,您的inputAccessoryToolbar既是视图控制器的视图,也是文本视图的输入附件视图.

That way, your inputAccessoryToolbar will be both your view controller's and your text view's input accessory view.

这篇关于取消键盘后使inputAccessoryView可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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