如何在不关闭键盘的情况下隐藏inputAccessoryView [英] How to hide inputAccessoryView without dismissing keyboard

查看:146
本文介绍了如何在不关闭键盘的情况下隐藏inputAccessoryView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在textView的inputAccessoryView属性中使用工具栏。当键盘显示时,它会按预期显示工具栏。旋转设备时,我想删除工具栏。我试过了:

I am using a toolbar in the inputAccessoryView property of a textView. When the keyboard shows, it displays the toolbar as expected. When the device is rotated I want to remove the toolbar. I tried:

 myTextView.inputAccessoryView.hidden = !layoutIsPortrait;

这会隐藏工具栏,但会留下较高的键盘轮廓。键盘显然仍然适合工具栏。它看起来很糟糕,会干扰底层响应者的触摸事件。

This does hide the toolbar, but leaves the outline of the taller keyboard behind. The keyboard is apparently still sized to fit the toolbar. It looks bad and interferes with touch events of underlying responders.

 myTextView.inputAccessoryView = nil;

仅当我resignFirstResponder,然后再次成为FirstResponder时才有效。这是不可接受的。我丢失了光标位置和textView的内容,键盘闪烁,然后返回。

Works only if I resignFirstResponder, then becomeFirstResponder again. This is not acceptable. I lose the cursor placement and content of the textView, keyboard flashes out and back.

[myTextView.inputAccessoryView removefromSuperview];

什么都不做。
我在iVar中保存了对工具栏的引用并代替了它,

Does nothing at all. I saved a reference to the toolbar in a iVar and addressed that instead,

[myIvarReference removeFromSuperview];

这样可行,但键盘的较高轮廓再次隐约可见。这次它不会干扰其他视图的触摸。所以现在这是一个有效的解决方案,但在视觉上是不可接受的。
我还可以尝试显示和隐藏inputAccessoryView吗?

That works, but again the taller outline of the keyboard is faintly visible. This time it does not interfere with touches of other views. So now this is a working solution but visually unacceptable. What else can I try to show and hide the inputAccessoryView at will?

屏幕截图 - 键盘上方的微弱线条是已删除工具栏的残余

Screenshot- the faint line above the keyboard is remnant of the removed toolbar

推荐答案

从未找到改变键盘框架的方法。最终决定放弃inputAccessoryView,将我的工具栏直接添加到视图中作为子视图,并直接将其与键盘一起动画。这使两者保持独立,因此不再有线。

Never found a way to alter the frame of the keyboard. Ultimately decided to forego the inputAccessoryView, add my toolbar directly to the view as a subview and animate it myself along with the keyboard directly. This keeps the two independent and so, no more line.

这篇关于如何在不关闭键盘的情况下隐藏inputAccessoryView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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