iPhone X 等设备UITextField输入框自带的清空按钮,点击清空时失效,原因是:
在该界面添加了如下隐藏键盘的方法,导致点击UITextField的清空按钮失效
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
tapGestureRecognizer.delegate=self;
- (void)keyboardHide:(UITapGestureRecognizer*)tap {
[self.backViewendEditing:YES];
}
解决方式:
1、先设置当前界面为tapGestureRecognizer的代理,并遵守UIGestureRecognizerDelegate协议
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)];
tapGestureRecognizer.delegate=self;
2、实现代理方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch {
if ([touch.view isKindOfClass:[UIButton class]]) {
returnNO;
}
return YES;
}