失去第一响应者基本上都是运用到隐藏键盘上的,大致代码如下:
此方法写在ViewDidLoad里面
UITapGestureRecognizer *tapHide = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
tapHide.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapHide]; </span>
调用的方法为
-(void)viewTapped:(UITapGestureRecognizer*)tapGr
{
[self.view endEditing:YES];
}</span>
[self.viewendEditing:YES]; 此代码是让整个View失去响应者 从而达到键盘隐藏的效果
PS:如果有多层View覆盖要记得给View添加上去点击手势