在自定义键盘中正确实现handleInputModeList

iOS 10中添加了一个新API,用于显示用户可以切换到的其他键盘列表 – 用户在系统键盘上长按地球仪时显示的相同列表。 该function的声明如下:
func handleInputModeList(from view: UIView, with event: UIEvent)

我的问题是,生成UIEvent供应的正确方法是什么? 我打算使用UILongPressGestureRecognizer调用此函数,但此API不会显示UIEvent

我这是错误的。 无需自定义手势处理。 如标题中所述,应该将一个target-action添加到他们想要触发它的控件中,如下所示:

Objective-C的:
[keyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];

迅速:
keyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: UIControlEvents.allTouchEvents)