Reputation: 83
I want to hide the keyboard if the user clicks on a textfield. Does anybody have an idea how to do that in swift 2?
Upvotes: 1
Views: 402
Reputation: 119021
Showing a text field on screen doesn't mean that only a text field is there. You could have a text field as a sub view, with user interaction disabled. Then, add a transparent button as a sibling view with the same frame (ensuring it's in front). When the button is tapped, which from a user point of view is tapping the text field, you can show your picker.
The text field also offers direct support for displaying a picker view by allowing you to set its inputView.
Upvotes: 0
Reputation: 4286
Make sure to set the text field delegate and return false
in this UITextFieldDelegate method:
func textFieldShouldBeginEditing(textField: UITextField) -> Bool {
return false
}
This will prevent the keyboard from showing. You can also place the code to open the picker in that method.
Upvotes: 4