How can I detect when the keyboard is shown and hidden from my application?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
You may just need
addObserver
inviewDidLoad
. But havingaddObserver
inviewWillAppear
andremoveObserver
inviewWillDisappear
prevents rare crashes which happens when you are changing your view.Swift 4.2
Swift 3 and 4
Older Swift
You'll want to register yourself for the 2 keyboard notifications:
Great post on how to adjust your TextField to the keyboard - http://iosdevelopertips.com/user-interface/adjust-textfield-hidden-by-keyboard.html
In Swift 4.2 the notification names have moved to a different namespace. So now it's
There is a CocoaPods to facilitate the observation on
NSNotificationCentr
for the keyboard's visibility here: https://github.com/levantAJ/Keyhipod 'Keyhi'
Swift - 4
Swift 3: