http://stackoverflow.com/questions/5306240/iphone-dismiss-keyboard-when-touching-outside-of-textfield
You'll need to add an UITapGestureRecogniser and assign it to the view, and then call resign first responder on the textfield on it's selector.
The code:
In viewDidLoad
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
In dismissKeyboard:
-(void)dismissKeyboard {
[aTextField resignFirstResponder];
}
(Where aTextField is the textfield that is responsible for the keyboard)
本文介绍了一种在iPhone应用中实现当触摸屏幕除文本框外的其他区域时自动隐藏软键盘的方法。通过添加UITapGestureRecognizer并设置相应的事件响应,可以轻松实现这一功能。
3668

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



