ios 可以在不使用 UITextField 和 UITextView iphone 应用程序的情况下显示键盘吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13005969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
It is possible to show keyboard without using UITextField and UITextView iphone app?
提问by Gopinath
I am working in iPhone messaging based app.
我正在使用基于 iPhone 消息的应用程序。
I want to show keyboard with keyboard inputAccessoryView
in keyboard without using UITextView
and UITextField
. It is possible to do this? Please any one help me on this.
我想inputAccessoryView
在不使用UITextView
和的情况下在键盘中显示带有键盘的键盘UITextField
。有可能做到这一点吗?请任何人帮助我。
Thanks in advance. Looking forward your help. Thanks.
提前致谢。期待您的帮助。谢谢。
EDIT:
编辑:
Because i don't want the UITextField
/UITextView
and the control to be in UITextView
/UITextField
. I am going to add inputAccessoryView
on the keyboard is UITextView
. when the user touches the UITextview
in the keyboard inputView
the actual process will be continue.
因为我不希望UITextField
/UITextView
和控件位于UITextView
/ 中UITextField
。我要inputAccessoryView
在键盘上添加的是UITextView
。当用户触摸UITextview
键盘中inputView
的 时,实际过程将继续。
回答by Oleksandr Skrypnyk
For anyone, who wants to show keyboard without UITextField
/UITextView
for some reasons, could easily extend some view, which requires text input by implementing UIKeyInput
protocol and canBecomeFirstResponder
method.
对于出于某些原因想要在没有UITextField
/UITextView
的情况下显示键盘的任何人,可以轻松扩展一些视图,这需要通过实现UIKeyInput
协议和canBecomeFirstResponder
方法来输入文本。
回答by Kostub Deshmukh
See the documentation for doing that here:
请参阅此处的文档:
All you need to do is have your view implement UIKeyInput
and call [inputView becomeFirstResponder]
when the view is touched. Your view also needs to implement canBecomeFirstResponder
and return YES.
您需要做的就是让您的视图实现UIKeyInput
并[inputView becomeFirstResponder]
在触摸视图时调用。您的视图还需要实现canBecomeFirstResponder
并返回 YES。
回答by iPhone Programmatically
You can try the answers on these other SO posts:
您可以在这些其他 SO 帖子中尝试答案:
You can also try this:
你也可以试试这个:
UIKeyboard *keyboard = [[[UIKeyboard alloc] initWithFrame: CGRectMake(0.0f, contentRect.size.height - 216.0f, contentRect.size.width, 216.0f)] autorelease];
[keyboard setReturnKeyEnabled:NO];
[keyboard setTapDelegate:editingTextView];
[inputView addSubview:keyboard];
回答by eonist
In xcode simulator:
在 xcode 模拟器中:
Sometimes the keyboard wont show because the software keyboard is off. Go to hardware -> Keyboard -> toggle keyboard
有时键盘不会显示,因为软键盘已关闭。转到硬件 -> 键盘 -> 切换键盘
回答by alegelos
Make a View, Label or what ever to conform to UIKeyInput. In this case a UIView
制作一个视图、标签或任何符合 UIKeyInput 的东西。在这种情况下,一个 UIView
Sub class a UIView:
子类 UIView:
import UIKit
class KeyInputView: UIView {
var _inputView: UIView?
override var canBecomeFirstResponder: Bool { return true }
override var canResignFirstResponder: Bool { return true }
override var inputView: UIView? {
set { _inputView = newValue }
get { return _inputView }
}
}
// MARK: - UIKeyInput
//Modify if need more functionality
extension KeyInputView: UIKeyInput {
var hasText: Bool { return false }
func insertText(_ text: String) {}
func deleteBackward() {}
}
Setup your View, in this case with a picker (in viewDidLoad or where ever)
设置您的视图,在这种情况下使用选择器(在 viewDidLoad 或任何地方)
let languangePicker = UIPickerView()
languangePicker.dataSource = self
languangePicker.delegate = self
keyInputView.inputView = languangePicker
To show:
显示:
keyInputView.becomeFirstResponder()
To hide:
隐藏:
keyInputView.resignFirstResponder()
Set picker data, from datasource (compiler force u to do it)
从数据源设置选择器数据(编译器强制你这样做)
Grab data picker events from delegate
从委托中获取数据选择器事件
回答by Mindhavok
I have made a small utility file that can call a Keyboard with a textfield on a button touch !
我制作了一个小实用程序文件,可以通过按钮触摸调用带有文本字段的键盘!