首先输入完成后按键盘上的done关闭键盘

首先在Interface Builder中选择TextFields,然后在Text Field Attributes中找到Text Input Traits,选择Return Key为done。OK

定义方法

- (IBAction) textFieldDoneEditing:(id)sender; //按下Done键关闭键盘

实现方法

//按完Done键以后关闭键盘

- (IBAction) textFieldDoneEditing:(id)sender

{

[sender resignFirstResponder];

}

然后找到事件Did End On Exit,与textFieldDoneEditing关联,OK。 

 

如果是数字键盘,没有done键怎么办呢,我们通过触摸背景关闭键盘

定义方法

- (IBAction) backgroundTap:(id)sender; //通过触摸背景关闭键盘

实现方法

//通过触摸背景关闭键盘

- (IBAction) backgroundTap:(id)sender

{

[nameFiled resignFirstResponder];

[numberField resignFirstResponder];

}

然后选择背景的Touch Down事件,关联 backgroundTap,OK

 

 

相关文章:

  • 2021-12-28
  • 2021-07-07
  • 2022-12-23
  • 2021-11-17
  • 2021-11-05
  • 2022-01-08
  • 2022-12-23
猜你喜欢
  • 2021-09-05
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-09-06
相关资源
相似解决方案