通过检查条件防止 UITextField 聚焦?

Prevent UITextField from focusing by checking a condition?

我想检查用户触摸 UITextField 时的情况,以防止它在某些情况下聚焦和显示键盘。

您可以使用 UITextFieldDelegate 中可用的 textFieldShouldBeginEditing 方法。

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
    if condition {  // Specify your condition
        return true
    }
    return false
}