指定文本框代理
- (void)viewDidLoad {
[ super viewDidLoad];
txt.delegate = self;
}
按回车隐藏键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
点击view其它地方隐藏键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[txt resignFirstResponder];
}
//触摸事件
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
本文介绍了一个iOS应用中如何通过设置文本框代理、监听触摸事件等方式实现键盘的显示和隐藏功能,包括按回车键隐藏键盘及点击视图其他区域隐藏键盘的方法。
7626

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



