我怎么知道编辑是在以 UIPickerView 作为输入的 UITextField 上开始的?

How can I know that editing began on a UITextField that has a UIPickerView as input?

我将 UIPickerView 设置为 UITextField 的输入。我如何知道用户何时按下了 UITextField?

我试过 TouchDownEditingDidStart 事件,但它们不会触发。

我link方法的事件代码如下

myTextField.addTarget(self, action: #selector(myMethod), for: .<Event>)

使用 UITextFieldDelegate

的委托方法 func textFieldDidBeginEditing(_ textField: UITextField)

并且不要忘记成为像 yourTextField.delegate = self 这样的文本字段代表 https://developer.apple.com/documentation/uikit/uitextfielddelegate/1619590-textfielddidbeginediting

您需要在您的项目中添加 UITextFieldDelegate,然后将其委托给您的文本字段,例如:

class yourClassName: UIViewController , UITextFieldDelegate  {

    @IBOutlet weak var yourTextField: UITextField!

override func viewDidLoad() 
    {
    super.viewDidLoad()
    yourTextField.delegate = self
    }
} 

并且您需要实施

func textFieldDidBeginEditing(_ textField: UITextField) {
    //Code here
}