![](/img/trans.png)
[英]iPhone - possible to not show keyboard but still show the cursor in a UITextField?
[英]It is possible to show keyboard without using UITextField and UITextView iphone app?
我正在使用基于iPhone消息传递的应用程序。
我想在不使用UITextView
和UITextField
情况下在键盘中显示带键盘inputAccessoryView
的键盘。 有可能这样做吗? 请任何人帮我这个。
提前致谢。 期待你的帮助。 谢谢。
编辑:
因为我不希望UITextField
/ UITextView
和控件在UITextView
/ UITextField
。 我要在键盘上添加inputAccessoryView
是UITextView
。 当用户触摸键盘UITextview
中的inputView
,实际过程将继续。
对于任何想要在没有UITextField
/ UITextView
情况下显示键盘的人,可以轻松扩展一些视图,这需要通过实现UIKeyInput
协议和canBecomeFirstResponder
方法来输入文本。
请参阅此处的文档:
您需要做的就是让视图实现UIKeyInput
并在触摸视图时调用[inputView becomeFirstResponder]
。 您的视图还需要实现canBecomeFirstResponder
并返回YES。
您可以尝试这些其他SO帖子的答案:
你也可以试试这个:
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];
有时键盘不会显示,因为软键盘已关闭。 转到硬件 - >键盘 - >切换键盘👌
我做了一个小实用程序文件,可以通过按钮触摸调用带有文本字段的键盘!
制作视图,标签或任何符合UIKeyInput的内容。 在这种情况下,UIView
子类a 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() {}
}
设置您的视图,在这种情况下使用选择器(在viewDidLoad或任何地方)
let languangePicker = UIPickerView()
languangePicker.dataSource = self
languangePicker.delegate = self
keyInputView.inputView = languangePicker
显示:
keyInputView.becomeFirstResponder()
隐藏:
keyInputView.resignFirstResponder()
从数据源设置选择器数据(编译器强制你去做)
从委托中获取数据选择器事件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.