Introduction
Welcome to the documentation page for WHC KeyboardManager. This library simplifies keyboard handling in your iOS app, making it easier to manage keyboard events and improve user experience. This page will provide you with all the necessary information to start using WHC KeyboardManager in your projects.
Installation
To install WHC KeyboardManager in your project, follow these steps:
- Open your terminal and navigate to the root directory of your Xcode project.
- Run the following command to install WHC KeyboardManager using Cocoapods:
pod 'WHC_KeyboardManager'
If you don’t have Cocoapods installed, please visit Cocoapods website and follow the installation guide.
Getting Started
Once you have WHC KeyboardManager installed in your project, you can start using it by following these steps:
- Import the WHC KeyboardManager at the top of your relevant file:
import KeyboardManager
- In your view controller, create an instance of WHC KeyboardManager:
let keyboardManager = WHCKeyboardManager()
- Register your view controller to receive keyboard notifications:
keyboardManager.addKeyboardDelegate(self)
- Implement the necessary keyboard delegate methods in your view controller:
func keyboardWillShow(with height: CGFloat) {
// Handle keyboard will show event
}
func keyboardWillHide() {
// Handle keyboard will hide event
}
Features
WHC KeyboardManager offers the following features:
- Automatic adjustment of the scroll view’s contentInset and scrollIndicatorInsets when the keyboard appears/disappears.
- Handling tap gesture to dismiss the keyboard.
- Swipe gesture to dismiss the keyboard.
- Adjustment of the scroll view’s contentOffset when the keyboard obscures edit fields.
- Support for external input views such as accessory input view, custom input view, etc.
- Customizable animation options for keyboard appearance/disappearance.
Delegate Methods
WHC KeyboardManager provides the following delegate methods to handle keyboard events:
keyboardWillShow(with height: CGFloat)
: Called when the keyboard is about to be displayed. Provides the height of the keyboard.keyboardWillHide()
: Called when the keyboard is about to be hidden.
Examples
Here are a few examples demonstrating the usage of WHC KeyboardManager:
Example 1: Basic Implementation
Implementing keyboard handling in a view controller using WHC KeyboardManager:
import UIKit
import KeyboardManager
class ViewController: UIViewController, WHCKeyboardDelegate {
let keyboardManager = WHCKeyboardManager()
override func viewDidLoad() {
super.viewDidLoad()
keyboardManager.addKeyboardDelegate(self)
}
func keyboardWillShow(with height: CGFloat) {
// Handle keyboard will show event
}
func keyboardWillHide() {
// Handle keyboard will hide event
}
}
Example 2: Customization
Customizing the keyboard appearance and animation options:
import UIKit
import KeyboardManager
class CustomViewController: UIViewController, WHCKeyboardDelegate {
let keyboardManager = WHCKeyboardManager(animationOptions: .curveEaseInOut)
override func viewDidLoad() {
super.viewDidLoad()
keyboardManager.addKeyboardDelegate(self)
}
func keyboardWillShow(with height: CGFloat) {
// Handle keyboard will show event
}
func keyboardWillHide() {
// Handle keyboard will hide event
}
}
Conclusion
Congratulations! You have successfully integrated WHC KeyboardManager into your iOS app. With this library, you can now easily manage keyboard events and improve the user experience of your app. If you have any questions or need further assistance, feel free to reach out to our support team or consult the official GitHub repository for more information.