想知道每次在文本字段编辑iOS期间按下键盘上的后退按钮时 [英] want to know ever time while pressing on keyboard back button during textfield editing ios
本文介绍了想知道每次在文本字段编辑iOS期间按下键盘上的后退按钮时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在OTP中,使用了四个文本字段.在按住键盘后退按钮的同时将光标移至上一个文本字段?
In OTP, there are four textfields were used. Moving the cursor to the previous textfield while pressing on keyboard back button?
推荐答案
创建UITextField
的子类.然后覆盖deleteBackward
方法.最后,通过确认BackSpaceDelegate
协议,使自定义delegate
来检测目标类中的退格键.这里给你一个演示:
Make a subclass of UITextField
. Then override the deleteBackward
method. At last make custom delegate
to detect backspace in your target class by confirming the BackSpaceDelegate
protocol. Here give you a demo:
protocol BackSpaceDelegate {
func deleteBackWord(textField: CustomTextField)
}
class CustomTextField: UITextField {
var backSpaceDelegate: BackSpaceDelegate?
override func deleteBackward() {
super.deleteBackward()
// called when textfield is empty. you can customize yourself.
if text?.isEmpty ?? false {
backSpaceDelegate?.deleteBackWord(textField: self)
}
}
}
class YourViewController: UIViewController, BackSpaceDelegate {
func deleteBackWord(textField: CustomTextField) {
/// do your stuff here. That means resign or become first responder your expected textfield.
}
}
希望这会对您有所帮助.
Hope this will help you.
这篇关于想知道每次在文本字段编辑iOS期间按下键盘上的后退按钮时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文