IOS点击空白处隐藏键盘 和 滑动空白处隐藏键盘的方法

- (void)viewDidLoad {
    [super viewDidLoad];

// 点击空白处收键盘
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fingerTapped:)];
    [self.view addGestureRecognizer:singleTap];
}

#pragma mark --收起键盘
// 滑动空白处隐藏键盘
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    [self.view endEditing:YES];
}

// 点击空白处收键盘
-(void)fingerTapped:(UITapGestureRecognizer *)gestureRecognizer { 
    [self.view endEditing:YES];    
}

你可能感兴趣的:(IOS点击空白处隐藏键盘 和 滑动空白处隐藏键盘的方法)