是否有一种标准方法可以确保键盘出现在屏幕上并且不会消失?我已将我的 textView
设置为第一响应者,以确保键盘显示,但我希望文本出现在 textView
中(让用户知道要输入什么字段),当我成为第一响应者时,我会自动调用 textViewDidBeginEditing:
,这是我最初将文本设置为 @""
的地方,在它最初被设置为 @“用户说明”
。
最佳答案
您可以使用 NSNotificationCenter 将通知设置为检测键盘何时出现或消失。
- (void)viewDidLoad
{
[super viewDidLoad];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide)
name:UIKeyboardWillHideNotification
object:nil];
}
在这些方法中你可以处理任何你想要的
-(void)keyboardWillShow
{
}
-(void)keyboardWillHide
{
}
关于ios - becomeFirstResponder 而不调用 textViewDidBeginEditing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25945440/