如何以上方视图显示键盘? [英] How do I show the keyboard with a view above it?
问题描述
当用户点击一个按钮时,我希望弹出键盘(这很简单),但是我希望视图随之上升(保持在键盘顶部).该视图将具有发送消息.."文本字段.当用户按完成时,我希望键盘与视图一起消失.
When a user taps on a button, I'd like the keyboard to pop up (which is easy), but I want a view that goes up along with it (sticking to the top of the keyboard). This view will be have a "send a message.." textfield. When the user pushes done, I want the keyboard to go away along with the view.
如何使该视图粘"在键盘上?
How do I make this view "stick" to the keyboard?
推荐答案
UITextFields具有一个名为inputAccessoryView
UITextFields have a property called inputAccessoryView
这会将您分配为该文本字段的inputAccessoryView的任何视图固定在键盘顶部.
This will pin whatever view you assign as that textfield's inputAccessoryView to the top of the keyboard.
从该链接的答案中记住的重要内容:
Something important from the answer in that link to remember:
请注意,您使用的视图既不应位于其他视图层次结构中,也不应将其添加到某些超级视图中,这是为您完成的.
Note that the view you use should neither be in the view hierarchy elsewhere, nor should you add it to some superview, this is done for you.
这篇关于如何以上方视图显示键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!