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
If I got you right you want to resign keyboard wile tapping on outSide of
textfield
but you don't have reference of yourtextfield
.Try this;
reftextField
Now in
textFieldDidBeginEditing
set referenced text field toNow you can happily use on any button clock, (adding a transparent button on begin editing recomended)
Or for resigning done button try this.
You can create category for the UiView and override the touchesBegan meathod as follows.
It is working fine for me.And it is centralize solution for this problem.
This is a good generic solution:
Objective-C:
Swift:
Based on @icodebuster solution: https://stackoverflow.com/a/18756253/417652
It is better to make your
UIView
an instance ofUIControl
(in interface builder) and then connect theirTouchUpInside
event todismissKeyboard
method. ThisIBAction
method will look like:I used Barry example for my new development. It worked great! but i had to include a slightly change, required to dismiss the keyboard only for the textfield being edited.
So, I added to Barry example the following:
Also, I changed hideKeyboard method as follows: