我们制作了一个自定义键盘,并上传到App,设计和键盘工作良好。然而,由于按钮的缓慢性,我们得到了很多1星级的评论。问题是。有办法加快UIButtons的速度吗?
一旦用户从按钮上松开手指,UIControl的touchUpInside就能工作,在某些情况下,人们写得太快,而touchUpInside不是“快速”的方法。
TouchDown会在TouchUpInside之前开火,因为触碰是指你的手指在手机上触下的动作。
请就此提出建议,对于生产键盘,您通常喜欢哪种方式?
这是我目前处理水龙头的方法:太慢了!
func buttonAction(_ sender:UIButton!) {
print("Button tapped")
self.textDocumentProxy.insert("B")
}发布于 2018-04-01 12:50:39
TouchDown和TouchUpInside的速度并不是真正的问题。当用户使用双拇指打字时,问题就出现了,而关键的笔画被按错误的顺序解释。
苹果的默认键盘在升级时会注册一个键。但是,在iPhone上,如果在第一个键被关闭时按下了第二个键,那么第一个键就会被注册,而不会等待它的修改。这使输入保持按按压顺序(用于两次拇指输入),但仍然反映了触摸的行为。
要实现这一点,您需要同时观察TouchDown和TouchUpInside事件。
这是你可以做的一种方法。创建一个名为pendingButton的属性来跟踪按下的最后一个按钮,并在松开按钮或按下另一个按钮时处理该按钮。
您需要将buttonDown连接到TouchDown事件,将buttonUp连接到TouchUpInside事件。
// last button pressed down
var pendingButton: String?
// connect button TouchDown events here
@IBAction func buttonDown(_ sender: UIButton) {
// If we already have a pending button, process it before storing
// the next one
if let pending = self.pendingButton {
self.textDocumentProxy.insert(pending)
}
self.pendingButton = sender.currentTitle
}
// connect button TouchUpInside events here
@IBAction func buttonUp(_ sender: UIButton) {
// If the button being let up is the latest pending button,
// then process it, otherwise ignore it
if sender.currentTitle == self.pendingButton {
self.textDocumentProxy.insert(self.currentTitle!)
self.pendingButton = nil
}
}注意:,您可能还需要仔细考虑其他事件,如TouchUpOutside。这可能也应该连接到buttonUp,这取决于您的键盘的期望行为。
如果将按钮拖到外部取消按钮,则应该实现一个函数来观察TouchDragExit,如果这是挂起按钮,则取消挂起按钮。
// connect button TouchDragExit events here
@IBAction func dragExit(_ sender: UIButton) {
if sender.currentTitle == self.pendingButton {
self.pendingButton = nil
}
}发布于 2019-09-11 12:11:23
加速使用调度队列的最简单方法
DispatchQueue.main.async {
self.textDocumentProxy.insertText(self.currentTitle!)}我这样做了,速度和原来的键盘一样快。
https://stackoverflow.com/questions/49596517
复制相似问题