Overview
IQKeyboardManager is a code-less drop-in library that automatically prevents the keyboard from covering UITextField/UITextView. This guide will walk you through the basic setup process.Installation
First, install IQKeyboardManager using your preferred package manager:Basic Configuration
Enable IQKeyboardManager
Enable the manager in
application(_:didFinishLaunchingWithOptions:):AppDelegate.swift
That’s it! With just one line of code, IQKeyboardManager will automatically handle keyboard avoidance for all text fields in your app.
Optional Configuration
You can customize the default keyboard distance:AppDelegate.swift
SwiftUI Apps
For SwiftUI apps using@main, configure IQKeyboardManager in your App struct:
App.swift
What Happens Behind the Scenes
When enabled, IQKeyboardManager:- Observes keyboard show/hide notifications
- Detects the active text input view
- Calculates the required adjustment to prevent keyboard overlap
- Smoothly animates the view to the correct position
- Restores the original position when the keyboard is dismissed
Verification
To verify IQKeyboardManager is working correctly:- Create a form with multiple text fields
- Tap on a text field at the bottom of the screen
- The view should automatically scroll up to show the text field above the keyboard
- Tap outside the text field or press the return key
- The view should smoothly return to its original position
IQKeyboardManager is thread-safe and all APIs must be called from the main thread. The class is marked with
@MainActor to enforce this at compile time.Next Steps
Advanced Configuration
Learn about class-level controls and view-specific overrides
Toolbar Management
Add Previous/Next/Done buttons to the keyboard
Debugging
Enable debug logging to troubleshoot issues
API Reference
Explore all available properties and methods