iOS點擊空白處或點擊背景收起鍵盤

1.在viewDidLoad中添加手勢app

- (void)viewDidLoad{get

[super viewDidLoad];it

//添加手勢io

UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
tap1.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tap1];select

}方法

 

而後 實現方法便可
-(void)viewTapped:(UITapGestureRecognizer*)tap1
{di

[self.view endEditing:YES];view

}vi

相關文章
相關標籤/搜索