如何关闭自定义键盘中的键盘?

How do I dismiss the keyboard in a custom keyboard?

我想将自定义键盘上的 key/button 分配给 dismiss/hide 键盘。我似乎无法使用任何代码。

我试过:

self.view.resignFirstRespoder()

view.endEditing(true)

但这些思路似乎都不起作用。

有人能给我指出正确的方向吗?

调用dismissKeyboard()函数。

Because a custom keyboard does not have access to the current text input object, you cannot send it a resignFirstResponder() message (as you would to dismiss the system keyboard when you are developing an app with text entry). To dismiss the custom keyboard, call dismissKeyboard() instead.

Apple reference.