2

我正在尝试创建 iPad 应用程序,它有两个UIViews (如UISplitView)。有UISearchDisplayController在“主人”的一面。

我需要通过点击外部(“主”或“细节”侧)来关闭键盘。现在我只能通过点击其中的关闭按钮或点击来关闭键盘UISearchDisplayController

在rmaddy的帮助下解决

@interface MyViewController : UIViewController <UIGestureRecognizerDelegate>
...
...
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard:)];
tapGesture.delegate = self;
[self.view addGestureRecognizer:tapGesture];
...
...
- (void)dismissKeyboard:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded) {
        self.searchDisplayController.active = NO;
    }
}
4

0 回答 0