没有键盘的 UITextField 功能 [英] UITextField functionality with no keyboard

查看:21
本文介绍了没有键盘的 UITextField 功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个带有用于输入文本的自定义界面的应用程序,并使用 UILabel 进行显示.然后用户必须能够复制和粘贴文本,所以我使用了 UITextField.

I am building an application with a custom interface for entering text, and was using a UILabel for display. It then became necessary for the user to be able to copy and paste the text, so I went with a UITextField.

我遇到的问题是我不知道如何让 UITextField 允许选择、复制、粘贴等,但在选择字段时没有显示键盘.

The problem I have is that I can't figure out how to get the UITextField to allow selection, copy, paste, etc, but have no keyboard displayed when the field is selected.

我已经阅读了许多与此类似的帖子,但没有一个提出完全相同的问题,也没有任何解决方案对我有用.我试过使该字段不可编辑,这确实阻止了键盘的出现,但也不允许复制和粘贴.我还阅读了建议对 UITextField 进行子类化的评论,但我读过的都没有给出具体的例子.

I have read numerous posts similar to this but none ask exactly the same thing, nor do any of the solutions work for me. I've tried making the field non-editable, which does block the keyboard from coming up, but also doesn't allow copying and pasting. I've also read comments suggesting subclassing the UITextField, but none I've read have given concrete examples.

可以简单地完成我想要的操作,还是我需要为键盘或其他选项创建自定义视图?

Can what I want be done simply, or do I need to go the route of creating a custom view for the keyboard, or other options?

谢谢,安德鲁

解决方案:

最后,我在 stackoverflow 上发现了另一个类似(但不准确)的问题,一个答案为我的问题提供了解决方案.实现它的方法很简单,就是让应用程序显示一个虚拟视图作为键盘,其他一切都按它应该的方式工作.

In the end, I discovered another similar (but not exact) question here on stackoverflow, and one answer gave a solution to my problem. The way to go about it is simply to have the app display a dummy View as the keyboard, and everything else works the way it should.

UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];    
VIN.inputView = dummyView; // Hide keyboard, but show blinking cursor

它适用于 UITextField 和 UITextView,它们需要设置为可编辑.

It works for UITextField and UITextView and they need to be set to editable.

推荐答案

解决方案:

最后,我在 stackoverflow 上发现了另一个类似(但不准确)的问题,一个答案为我的问题提供了解决方案.实现它的方法很简单,就是让应用程序显示一个虚拟视图作为键盘,其他一切都按它应该的方式工作.

In the end, I discovered another similar (but not exact) question here on stackoverflow, and one answer gave a solution to my problem. The way to go about it is simply to have the app display a dummy View as the keyboard, and everything else works the way it should.

UIView *dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];    
VIN.inputView = dummyView; // Hide keyboard, but show blinking cursor

它适用于 UITextFieldUITextView 并且它们需要设置为可编辑.

It works for UITextField and UITextView and they need to be set to editable.

这篇关于没有键盘的 UITextField 功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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