https://github.com/cokaholic/tkkeyboardcontrol
TKKeyboardControl adds keyboard awareness and scrolling dismissal (like iMessages app) to any view with only 1 line of code for Swift.
https://github.com/cokaholic/tkkeyboardcontrol
cocoapods facebook iphone-x iphonex keyboard messenger safearea safeareainsets swift swift4 textfield textview
Last synced: about 2 months ago
JSON representation
TKKeyboardControl adds keyboard awareness and scrolling dismissal (like iMessages app) to any view with only 1 line of code for Swift.
- Host: GitHub
- URL: https://github.com/cokaholic/tkkeyboardcontrol
- Owner: cokaholic
- License: mit
- Created: 2016-04-25T03:44:10.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-19T06:12:18.000Z (over 7 years ago)
- Last Synced: 2025-04-03T14:43:35.364Z (2 months ago)
- Topics: cocoapods, facebook, iphone-x, iphonex, keyboard, messenger, safearea, safeareainsets, swift, swift4, textfield, textview
- Language: Swift
- Homepage:
- Size: 1.01 MB
- Stars: 116
- Watchers: 6
- Forks: 11
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TKKeyboardControl
TKKeyboardControl adds keyboard awareness and scrolling dismissal (like iMessages app) to any view with only 1 line of code **for Swift4** and it supports **SafeArea**.
This library is inspired by [DAKeyboardControl](https://github.com/danielamitay/DAKeyboardControl).
[](https://img.shields.io/badge/Cocoapods-compatible-brightgreen.svg?style=flat-square)
[](http://cocoapods.org/pods/TKKeyboardControl)
[](http://mit-license.org)

## Features
- [x] Keyboard closing without UIScrollView
- [x] Support `Swift4`
- [x] Support `Safe Area`## Installation
#### CocoaPods
TKKeyboardControl is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:```ruby
pod 'TKKeyboardControl', :git => 'https://github.com/cokaholic/TKKeyboardControl.git', :tag => '2.0.0'
```#### Manually
Add the [TKKeyboardControl](./TKKeyboardControl) directory to your project.
## Usage
Example project included (./Example)
### Adding pan-to-dismiss (functionality introduced in iMessages)
#### Frame based action handler
```swift
view.addKeyboardPanning(frameBasedActionHandler: { keyboardFrameInView, firstResponder, opening, closing in
// Move interface objects accordingly
// Animation block is handled for you
})
// Make sure to call self.view.removeKeyboardControl before the view is released.
// (It's the balancing call)
```#### Constraint based action handler
```swift
view.addKeyboardPanning(constraintBasedActionHandler: { keyboardFrameInView, firstResponder, opening, closing in
// Move interface objects accordingly
// Animation block is handled for you
})
// Make sure to call self.view.removeKeyboardControl before the view is released.
// (It's the balancing call)
```### Adding keyboard awareness (appearance and disappearance only)
#### Frame based action handler
```swift
view.addKeyboardNonpanning(frameBasedActionHandler: { keyboardFrameInView, firstResponder, opening, closing in
// Move interface objects accordingly
// Animation block is handled for you
})
// Make sure to call self.view.removeKeyboardControl before the view is released.
// (It's the balancing call)
```#### Constraint based action handler
```swift
view.addKeyboardNonpanning(constraintBasedActionHandler: { keyboardFrameInView, firstResponder, opening, closing in
// Move interface objects accordingly
// Animation block is handled for you
})
// Make sure to call self.view.removeKeyboardControl before the view is released.
// (It's the balancing call)
```### Supporting an above-keyboard input view
The `keyboardTriggerOffset` property allows you to choose at what point the user's finger "engages" the keyboard.
```swift
view.keyboardTriggerOffset = 44.0; // Input view frame heightview.addKeyboardNonpanning(frameBasedActionHandler: { keyboardFrameInView, firstResponder, opening, closing in
// Move interface objects accordingly
// Animation block is handled for you
})
// Make sure to call self.view.removeKeyboardControl before the view is released.
// (It's the balancing call)
```### Dismissing the keyboard (convenience method)
```swift
view.hideKeyboard()
```### Remove the NSNotification observer at the end of a VC's life (convenience method)
```swift
view.removeKeyboardControl()
```## Notes
### Automatic Reference Counting (ARC) support
`TKKeyboardControl` was made with ARC enabled by default.## Requirements
- Xcode 8.0 or greater
- iOS9.0 or greater
- Swift4.0 or greater## Author
Keisuke Tatsumi, [email protected]
## License
TKKeyboardControl is available under the MIT license.
### MIT License
Copyright (c) 2018 Keisuke Tatsumi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.