xxxx.m文件中
- (void)viewDidLoad {
[super viewDidLoad];
//加入下面代码即可
//点击屏幕空白处去掉键盘
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
tap.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tap];
}
// 然后在同一个xxx.m文件里函数实现就行了
//点击屏幕空白处去掉键盘实现
-(void)viewTapped:(UITapGestureRecognizer*)tap
{
[self.view endEditing:YES];
}