为关闭键盘添加时间处理方法:
h文件
-(IBAction)textFieldDoneEditing:(id)sender;
m文件
-(IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];
}
------- >
触摸背景关闭键盘
在Hello-.h文件中增加动作声明:
-(IBAction)backgroundTap:(id)sender;
在Hello-.m文件中增加动作实现:
-(IBAction)backgroundTap:(id)sender {
[txtField resignFirstResponder];
}连接动作和事件
为了使背景控件能够响应事件,我们需要背景View的父类(UIView)修改成为UIControl,UIControl是能够触发action
本文介绍在iOS应用开发中如何通过代码实现键盘的关闭操作。包括使用IBAction响应文本框编辑结束事件来关闭键盘的方法,以及通过触摸视图背景来触发键盘关闭的动作实现。

1693

被折叠的 条评论
为什么被折叠?



