KeyboardObserver alternatives and similar libraries
Based on the "Keyboard" category.
Alternatively, view KeyboardObserver alternatives based on common mentions on social networks and blogs.
-
IQKeyboardManager
Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more. -
TPKeyboardAvoiding
A drop-in universal solution for moving text fields out of the way of the keyboard in iOS -
IHKeyboardAvoiding
IHKeyboardAvoiding is an elegant solution for keeping any UIView visible when the keyboard is being shown - no UIScrollView required! -
MMNumberKeyboard
A simple keyboard to use with numbers and, optionally, a decimal point. -
NgKeyboardTracker
Objective-C library for tracking keyboard in iOS apps. -
YYKeyboardManager
iOS utility class allows you to access keyboard view and track keyboard animation. -
RFKeyboardToolbar
[iOS] Add customized buttons and toolbars to your UITextInputs. -
Toolbar
Awesome autolayout Toolbar. Toolbar is a library for iOS. You can easily create chat InputBar. -
KeyboardMan
KeyboardMan helps you to make keyboard animation. -
Ribbon
🎀 A simple cross-platform toolbar/custom input accessory view library for iOS & macOS. -
AutoKeyboardScrollView
AutoKeyboardScrollView is an UIScrollView subclass which makes showing and dismissing keyboard for UITextFields much easier. So called keyboard avoidance. -
KeyboardHideManager
Codeless manager to hide keyboard by tapping on views for iOS written in Swift -
RSKKeyboardAnimationObserver
Showing / dismissing keyboard animation in simple UIViewController category. -
DPKeyboardManager
Auto slide the view when keyboard appears
Appwrite - The open-source backend cloud platform
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of KeyboardObserver or a related project?
README
KeyboardObserver
For less complicated keyboard event handling.
Features
- Less complicated keyboard event handling.
- Do not use
Notification
, butevent
.
Difference
Without KeyboardObserver.swift
let keyboardNotifications: [Notification.Name] = [
.UIKeyboardWillShow,
.UIKeyboardWillHide,
.UIKeyboardWillChangeFrame,
]
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
keyboardNotifications.forEach {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardEventNotified:), name: $0, object: nil)
}
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
keyboardNotifications.forEach {
NotificationCenter.default.removeObserver(self, name: $0, object: nil)
}
}
@objc func keyboardEventNotified(notification: NSNotification) {
guard let userInfo = notification.userInfo else { return }
let keyboardFrameEnd = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
let curve = UIView.AnimationCurve(rawValue: (userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber).intValue)!
let options = UIView.AnimationOptions(rawValue: UInt(curve.rawValue << 16))
let duration = TimeInterval(truncating: userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as! NSNumber)
let bottom = keyboardFrameEnd.height - bottomLayoutGuide.length
UIView.animate(withDuration: duration, delay: 0.0, options: [options], animations:
{ () -> Void in
self.textView.contentInset.bottom = bottom
self.textView.scrollIndicatorInsets.bottom = bottom
} , completion: nil)
}
With KeyboardObserver
let keyboard = KeyboardObserver()
override func viewDidLoad() {
super.viewDidLoad()
keyboard.observe { [weak self] (event) -> Void in
guard let self = self else { return }
switch event.type {
case .willShow, .willHide, .willChangeFrame:
let keyboardFrameEnd = event.keyboardFrameEnd
let bottom = keyboardFrameEnd.height - self.bottomLayoutGuide.length
UIView.animate(withDuration: event.duration, delay: 0.0, options: [event.options], animations: { () -> Void in
self.textView.contentInset.bottom = bottom
self.textView.scrollIndicatorInsets.bottom = bottom
}, completion: nil)
default:
break
}
}
}
How to use
Create KeyboardObserver
instance where you want, and the instance observes keyboard untill deinit.
Call observe(event: KeyboardEvent)
to observe keyboard events. event
is converted keyboard notification object.
public struct KeyboardEvent {
public let type: KeyboardEventType
public let keyboardFrameBegin: CGRect
public let keyboardFrameEnd: CGRect
public let curve: UIViewAnimationCurve
public let duration: NSTimeInterval
public var isLocal: Bool?
public var options: UIViewAnimationOptions {
return UIViewAnimationOptions(rawValue: UInt(curve.rawValue << 16))
}
...
event
has properties above. You don't have to convert Notification
's userInfo to extract keyboard event values.
KeyboardEentType
has types same as keyboard's notification name. Like this below:
public enum KeyboardEventType {
case willShow
case didShow
case willHide
case didHide
case willChangeFrame
case didChangeFrame
...
}
It has also public var notificationName: String
which you can get original notification name.
Runtime Requirements
- iOS 8.0 or later
- Xcode 10.0
- Swift4.2
Installation and Setup
Information: To use KeyboardObserver with a project targeting lower than iOS 8.0, you must include the KeyboardObserver.swift
source file directly in your project.
Installing with Carthage
Just add to your Cartfile:
github "morizotter/KeyboardObserver"
Installing with CocoaPods
CocoaPods is a centralised dependency manager that automates the process of adding libraries to your Cocoa application. You can install it with the following command:
$ gem update
$ gem install cocoapods
$ pods --version
To integrate KeyboardObserver into your Xcode project using CocoaPods, specify it in your Podfile
and run pod install
.
platform :ios, '8.0'
use_frameworks!
pod "KeyboardObserver", '~> 2.1'
Manual Installation
To install KeyboardObserver without a dependency manager, please add KeyboardObserver.swift
to your Xcode Project.
Contribution
Please file issues or submit pull requests for anything you’d like to see! We're waiting! :)
License
KeyboardObserver.swift is released under the MIT license. Go read the LICENSE file for more information.
*Note that all licence references and agreements mentioned in the KeyboardObserver README section above
are relevant to that project's source code only.