我們經常會遇到這樣的需求,點擊空白收回鍵盤或者空白收回 鍵盤或者view绿鸣,
controller中又會有其他的cell淤刃,collectionview 等等摸恍,這里可以用到手勢的touch 傳遞鏈
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
//設置成NO表示當前控件響應后會傳播到其他控件上砸逊,默認為YES璧南。
tapGestureRecognizer.cancelsTouchesInView = NO;
//將觸摸事件添加到當前view
[self.view addGestureRecognizer:tapGestureRecognizer];
}
-(void)keyboardHide:(UITapGestureRecognizer*)tap{
[textFiled resignFirstResponder];
}