如何在没有动画的情况下隐藏键盘(或加速此动画)

How to hide keyboard without animation (or speed up this animation)

我的应用程序中有导航控制器和工具栏。在工具栏中是通过操作 "show detail" 显示 Table 视图控制器的栏项。当我单击取消时,此 Table 视图已关闭,但键盘一直等到 Table 视图控制器完全关闭。我想关闭键盘和 Table 视图。

这是我的“取消操作”按钮:

@IBAction func cancelTapped(sender: AnyObject) {

    self.nameTextField.becomeFirstResponder()
    self.caffeineTextField.becomeFirstResponder()
    self.dismissViewControllerAnimated(true, completion: nil)

}

您正在制作文本字段 First Responder,以便键盘保持打开状态。你应该 resignefirstResponder 从这些。其他关闭键盘的好方法是:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [[self view] endEditing:YES];
}