gpt4 book ai didi

ios - 我如何检测光标闪烁的时间 - ios - swift 4?

转载 作者:行者123 更新时间:2023-11-30 11:33:05 25 4
gpt4 key购买 nike

有没有办法在 swift 4 中检测光标闪烁?

实际上,我想在用户完成编辑后调用特定函数,而不是在编辑时调用。我使用了函数 textField(_ textField: UITextField, ShouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {}, func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { } 以及所有相关功能。当用户输入 1 个单词时会调用这些功能,但实际上,我想在用户输入所需的完整单词或字符后调用该函数。

最佳答案

shouldChangeCharactersInRange中设置计时器。当它触发时,您会知道无论您选择什么超时值都没有任何文本输入:

private var timer: Timer?

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
self.timer?.invalidate()
self.timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
// this is called 1 second after the last entry in the textfield
}
return true
}

关于ios - 我如何检测光标闪烁的时间 - ios - swift 4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50038309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com