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
This works
In this example, aTextField is the only UITextField.... If there are others or UITextViews, there's a tiny bit more to do.
Check this, this would be the easiest way to do that,
Or
This library will handle including scrollbar auto scrolling, tap space to hide the keyboard, etc...
https://github.com/michaeltyson/TPKeyboardAvoiding
Swift version, this works in combination with other elements (like a
UIButton
or anotherUITextField
):Add this code in your ViewController.m file :
I mashed up a few answers.
Use an ivar that gets initialized during
viewDidLoad:
Dismiss what ever is currently editing:
This must be the easiest way to hide your keyboard by touching outside :
(from How to dismiss keyboard when user tap other area outside textfield?)