iPhone - UITextView 的问题

iPhone - Problem with UITextView(iPhone - UITextView 的问题)
本文介绍了iPhone - UITextView 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

这可能是一件容易的事,但我就是想不通——如何结束编辑文本视图?如何让键盘消失?还是我必须在它外面点击才能让它消失?

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 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Is there a native YAML library for iPhone?(是否有适用于 iPhone 的本机 YAML 库?)
View aligned to top of keyboard appears in wrong place in iOS 9 Shortcut Bar only mode(在 iOS 9 Shortcut Bar only 模式下,与键盘顶部对齐的视图出现在错误的位置)
Disable speech to text button (Micro phone) on soft input keyboard in android programmatically(以编程方式在android中的软输入键盘上禁用语音到文本按钮(麦克风))
UIkeyboard type(UI键盘类型)
Android - customized keyboard key and action(Android - 自定义键盘按键和操作)
Android keyboard puts tab bar on top(Android键盘将标签栏放在顶部)