Swift - UITextField - 手势识别延迟
Swift - UITextField - Gesture recognizer delay
我正在使用 UITextField,我想在用户点击文本字段时触发一个函数,但我想在触发该函数之前等待 1/4 秒。
我该怎么做?
首先,您必须创建 IBAction,例如:changeTextField(见截图)
screenshot: create an IBAction for Editing changed event
第二次添加这段代码
@IBAction func changeTextField(sender: AnyObject) {
NSObject.cancelPreviousPerformRequestsWithTarget(self, selector: #selector(ViewController.functionWithDelay), object: nil)
self.performSelector(#selector(ViewController.functionWithDelay),
withObject: nil,
afterDelay: 1/4);
}
三、你函数
func functionWithDelay() {
print("running...")
}
我正在使用 UITextField,我想在用户点击文本字段时触发一个函数,但我想在触发该函数之前等待 1/4 秒。
我该怎么做?
首先,您必须创建 IBAction,例如:changeTextField(见截图)
screenshot: create an IBAction for Editing changed event
第二次添加这段代码
@IBAction func changeTextField(sender: AnyObject) {
NSObject.cancelPreviousPerformRequestsWithTarget(self, selector: #selector(ViewController.functionWithDelay), object: nil)
self.performSelector(#selector(ViewController.functionWithDelay),
withObject: nil,
afterDelay: 1/4);
}
三、你函数
func functionWithDelay() {
print("running...")
}