He *_*何一非 5 ios swift custom-keyboard
众所周知,iOS中的原始键盘可以通过长按取消按钮(⌫)来删除整个单词.
那么我们如何在Swift,iOS 8中为自定义键盘使用相同的功能呢?
注意:
我目前正在使用proxy.deleteBackward()删除字母,并使用:
var gesture = UILongPressGestureRecognizer(target: self, action: "longPressed:")
gesture.minimumPressDuration = 1.0
button.addGestureRecognizer(gesture)
Run Code Online (Sandbox Code Playgroud)
当按下按钮更长的时间.
谢谢!
我不确定你如何通过手势识别器来做到这一点。
原来的键盘行为是,
第一次按下按钮后,您可能应该继续调用删除函数并注意“X-time-interval”是否已过。伪代码是
var startTime: NSDate = NSDate()
var timer: NSTimer?
func deleteButtonPressed(deleteButton: UIButton) {
startTime = NSDate()
timer = NSTimer.scheduledTimerWithTimeInterval(0.4, target: self, selector: Selector("delete"), userInfo: nil, repeats: true)
}
func delete() {
if !deleteButton.highlighted {
timer.invalidate()
timer = nil
return
}
if ((currentNSDate - startTime ) < "X-time-Interval") {
// delete backward
} else {
/* figure out last space character in text and create NSRange
then
mytextView.text deleteCharactersInRange:theRange
set new text */
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1034 次 |
| 最近记录: |