I'm wondering how to make the keyboard disappear when the user touches outside of a UITextField
.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
Just to add to the list here my version of how to dismiss a keyboard on outside touch.
viewDidLoad:
Anywhere:
How about this: I know this is an old post. It might help someone :)
One of the most easiest and shortest way is to add this code to your
viewDidLoad
Set text fields delegate in view did load:
Add this Function:
Plenty of great answers here about using
UITapGestureRecognizer
--all of which breakUITextField
's clear (X) button. The solution is to suppress the gesture recognizer via its delegate:It's not the most robust solution but it works for me.
You can use UITapGestureRecongnizer method for dismissing keyboard by clicking outside of UITextField. By using this method whenever user will click outside of UITextField then keyboard will get dismiss. Below is the code snippet for using it.