問題描述
這可能是一件容易的事,但我就是想不通——如何結束編輯文本視圖?如何讓鍵盤消失?還是我必須在它外面點擊才能讓它消失?
This is probably an easy thing to do, but I just can't figure it out - how do I end editing athe textview? how can I get the keyboard to disappear? or do I have to click outside it to make it go away?
推薦答案
首先,像這樣一個(說實話)相當簡單的問題讓我想知道您是否嘗試過閱讀文檔或在互聯網上搜索.
First, a (to be honest) fairly simple question like this makes me wonder if you've tried reading the documentation, or searching on the internet.
搜索Apple 文檔 UITextView"為您提供 此鏈接 到類文檔.同樣,這里是文檔UITextViewDelegate.
Searching for "Apple documentation UITextView" gives you this link to the class documentation. Similarly, here is the documentation for the UITextViewDelegate.
搜索UITextView 簡單示例"會為您提供這個有用示例.
Searching for "UITextView simple example" gives you this useful example.
搜索UITextView 關閉鍵盤",第一個點擊似乎是 準確回答您的問題.(盡管他在返回鍵上關閉了鍵盤,這可能不是您想要的.)(編輯 - 從您的第二條評論看來,這正是您想要的.)
Searching for "UITextView dismiss keyboard", the first hit seems to answer your question exactly. (Although he dismisses the keyboard on a return key, which may not be what you want.) (Edit - it seems from your second comment it's exactly what you want.)
附:上面的人是正確的,如果有點簡潔(可以理解).你需要實現一個 UITextViewDelegate.在該委托中,如果您想在返回鍵上隱藏鍵盤,請實現 shouldChangeTextInRange,查找 @" " 并在收到第一響應者時辭職.或者,在您的 UI 中添加完成編輯"按鈕,并在用戶按下它時退出第一響應者.
P.S. The people above are correct, if a little terse (understandably). You need to implement a UITextViewDelegate. In that delegate, if you want to hide the keyboard on a return key, implement shouldChangeTextInRange, look for a @" " and resign first responder if you get it. Alternatively, add a "Done editing" button to your UI, and resign first responder if the user presses it.
這篇關于iPhone - UITextView 的問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!