我设计了一个具有以下层次结构的应用程序:
UIViewController
UIView
UIScrollView
UITextField
在 ViewDidLoad 我做了:
...
tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
tapGesture.cancelsTouchesInView = NO;
[self.scrollView addGestureRecognizer:tapGesture];
...
在 hideKeyboard 我做了:
- (void) hideKeyboard {
//Hide keyBoard
[self.view endEditing:YES];
}
乍一看,它工作得很好,但不幸的是有一个问题。当应用程序运行时,我们可以单击 UITextField,键盘按预期显示。如果我们单击 UITextField 之外,hideKeyboard
则会调用该方法并按预期关闭键盘,但如果您尝试再次单击 UITextField,则不会再次显示键盘。
我做错了什么?有人知道吗?