iOS點擊空白處或點擊背景收起鍵盤
在viewDidLoad中添加手勢
- (void)viewDidLoad{
[super viewDidLoad];
//添加手勢
UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];}
然後 實現方法即可
-(void)viewTapped:(UITapGestureRecognizer*)tap1
{
[self.view endEditing:YES];
}