在自定义键盘中正确实现 handleInputModeList [英] Proper implementation of handleInputModeList in Custom Keyboard
问题描述
iOS 10 中添加了一个新的 API,以显示用户可以切换到的其他键盘的列表 - 与用户在系统键盘上长按地球仪时显示的列表相同.函数声明如下:func handleInputModeList(from view: UIView, with event: UIEvent)
A new API has been added in iOS 10 to present the list of other keyboards the user can switch to - the same list that appears when users long press the globe on a system keyboard. The declaration of the function is as follows:
func handleInputModeList(from view: UIView, with event: UIEvent)
我的问题是,生成要提供的 UIEvent
的正确方法是什么?我打算使用 UILongPressGestureRecognizer
调用这个函数,但这个 API 没有显示 UIEvent
s.
My question is, what's the proper way to generate a UIEvent
to supply? I was planning to call this function using a UILongPressGestureRecognizer
but this API doesn't reveal UIEvent
s.
推荐答案
我的做法是错误的.无需自定义手势处理.如标题中所述,应该向他们想要触发此操作的控件添加一个目标操作,如下所示:
I was going about this the wrong way. No need for custom gesture handling. As noted in the headers, one should add a target-action to the control they want to trigger this, like so:
目标-C:[keyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];
斯威夫特:keyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: UIControlEvents.allTouchEvents)
这篇关于在自定义键盘中正确实现 handleInputModeList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!