在键盘上方添加 UITextField
Adding UITextField above Keyboard
我发现 link 如何在键盘上方创建工具栏。但是我不使用任何需要点击和显示键盘的文本字段。我的想法是按下 "Leave comment" 按钮,然后会出现带有文本字段的键盘。
所以在我附加的 link 中,他们似乎使用了与您交互的文本字段的 inputAccessoryView。但就我而言,我没有任何文本字段。
所以首先我需要在没有文本字段的情况下切换键盘,然后显示带有文本字段的键盘,例如键盘上方的栏。我怎样才能做到?
您好,您需要将 UITextfield
放在视图之外,
像这样:
ViewController.h
@property (strong, nonatomic) IBOutlet UITextField *_myTextField;
ViewController.m
UITextField *t = [UITextField new];
[self.view addSubview:t];
[t becomeFirstResponder];
t.inputAccessoryView = _myTextField;
查看结果:
我发现 link 如何在键盘上方创建工具栏。但是我不使用任何需要点击和显示键盘的文本字段。我的想法是按下 "Leave comment" 按钮,然后会出现带有文本字段的键盘。
所以在我附加的 link 中,他们似乎使用了与您交互的文本字段的 inputAccessoryView。但就我而言,我没有任何文本字段。
所以首先我需要在没有文本字段的情况下切换键盘,然后显示带有文本字段的键盘,例如键盘上方的栏。我怎样才能做到?
您好,您需要将 UITextfield
放在视图之外,
像这样:
ViewController.h
@property (strong, nonatomic) IBOutlet UITextField *_myTextField;
ViewController.m
UITextField *t = [UITextField new];
[self.view addSubview:t];
[t becomeFirstResponder];
t.inputAccessoryView = _myTextField;
查看结果: