当前位置:网站首页>监听iPad键盘显示和隐藏事件

监听iPad键盘显示和隐藏事件

2022-06-26 08:10:00 may_he

定义键盘显示事件

-(void)keyboardWillShow:(NSNotification *)notification

{

.....

}

定义输入完成后,按return键键盘隐藏

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

if([textField tag]==1)

{

[textField resignFirstResponder];

}

if(textField == editTextField)

{

[textField resignFirstResponder];

}

......

}


为虚拟键盘的右下角按钮定义事件

-(void)keyboardWillHide:(NSNotification *)notification

{

....

}

注册事件

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];


头文件中必须要有:

UITextFieldDelegate



原网站

版权声明
本文为[may_he]所创,转载请带上原文链接,感谢
https://blog.csdn.net/may_he/article/details/8450261