I am developing an app in which I want to open a view when the user clicks on a text field but I don't want to open the keyboard. How can I achieve this?
Asked
Active
Viewed 1,825 times
0
-
create a fake textfield or extend the textfield – Cerlin Mar 07 '18 at 11:41
4 Answers
4
You can easily achieve it by setting an empty custom input view to the textField
:
textField.inputView = UIView(frame: CGRect.zero)
Then the textField
can become first responder normally, but this view (with zero
frame) will be presented instead of the keyboard.

Milan Nosáľ
- 19,169
- 4
- 55
- 90
-
-
@V_rohit no need for a delegate, just set it anywhere where you configure the textField (that one line is all you need, call it once at the beginning when you configure the textfield) – Milan Nosáľ Mar 07 '18 at 12:11
-
3
Set your ViewController as your TextFields delegate using
self.yourTextfield.delegate = self
and now implement the UITextFieldDelegate as shown below
extension ViewController : UITextFieldDelegate {
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
//Load your VC here
return false
}
}
Thats all :) Hope it helps

Sandeep Bhandari
- 19,999
- 5
- 45
- 78
2
You can use below textField Delegate
Method
func textFieldDidBeginEditing(_ textField: UITextField) {
yourTextField.resignFirstResponder()
//code for show view
}
Hope it will help!

Kaushik Makwana
- 1,329
- 2
- 14
- 24
1
You can simply add a tap gesture recognizer to the text field.
let tapGestRec = UITapGestureRecognizer(target: self, action: #selector(textFieldTapped))
textField.addGestureRecognizer(tapGestRec)

Tamás Sengel
- 55,884
- 29
- 169
- 223