Configuration Architecture
IQKeyboardManager uses a multi-layered configuration system with three main components:IQActiveConfiguration
Coordinates keyboard and text input state
IQRootControllerConfiguration
Tracks view controller layout state
IQScrollViewConfiguration
Stores scroll view adjustments
IQActiveConfiguration
The central coordinator that manages the active keyboard session.Responsibilities
- Observes keyboard notifications via
IQKeyboardNotification - Monitors text input changes via
IQTextInputViewNotification - Determines when to trigger
adjustPosition()orrestorePosition() - Maintains current keyboard info and active text input view
- Manages root controller configuration lifecycle
Key Properties
Event System
IQActiveConfiguration sends three types of events:- Show - Keyboard appeared
- Change - Keyboard or text input changed
- Hide - Keyboard dismissed
IQRootControllerConfiguration
Captures and manages the root view controller’s initial layout state.Stored Properties
Computed Properties
Restoration
IQRootControllerConfiguration is created when a text input becomes active and stores the original layout state to enable restoration when the keyboard dismisses.IQScrollViewConfiguration
Manages scroll view state during keyboard adjustments.Stored Properties
State Management
Restoration
Content offset restoration
Content offset restoration
The
canRestoreContentOffset flag controls whether the scroll view’s content offset is restored when the keyboard dismisses.- Set to
truefor scroll views containing the text field - Set to
falsefor the text view itself (when it’s scrollable)
Global Settings
Configure IQKeyboardManager globally via the shared instance.Enable/Disable
Keyboard Distance
Set the default distance between keyboard and text input:- Must be non-negative
- Negative values log warnings
Layout Behavior
true, calls setNeedsLayout() and layoutIfNeeded() on each frame update.
Class-Level Control
Disable keyboard management for specific view controller types:If a class appears in both arrays,
disabledDistanceHandlingClasses takes precedence.Per-View Settings
All per-view configuration uses the.iq extension namespace.
Distance from Keyboard
Override the global keyboard distance for specific views:Enable Mode
Control keyboard management per text input view:Enable mode priority
Enable mode priority
IQKeyboardManager evaluates enable state in this order:
-
View-specific enable mode (
.iq.enableMode).enabled→ Always enabled.disabled→ Always disabled.default→ Continue to next check
-
View controller class lists
- If in
disabledDistanceHandlingClasses→ Disabled - If in
enabledDistanceHandlingClasses→ Enabled - Otherwise → Use global setting
- If in
-
Global setting (
IQKeyboardManager.shared.isEnabled)
ScrollView-Specific Settings
Control scroll view adjustment behavior using.iq extensions.
Ignore Scrolling Adjustment
Prevent IQKeyboardManager from adjusting a scroll view’s content offset:Ignore Content Inset Adjustment
Prevent IQKeyboardManager from modifying content insets:Restore Content Offset
Control whether content offset is restored when keyboard dismisses:Configuration Best Practices
1. Initialize Early
Enable IQKeyboardManager inAppDelegate:
2. Use Global Settings as Defaults
Set global defaults, then override per-view as needed:3. Disable for Special Controllers
Disable for view controllers with custom keyboard handling:4. Use Enable Modes Sparingly
Prefer class-level disabling over per-view enable modes:5. Test Scroll View Behavior
If you have nested scroll views, test thoroughly:6. Configure Distance by Density
Adjust keyboard distance based on UI density:7. Handle Layout Updates
For complex layouts, enable layout forcing:8. Document Custom Configuration
Add comments when using non-default settings:Configuration Persistence
IQKeyboardManager configuration is instance-based and persists for the app’s lifetime:Configuration is not persisted between app launches. Set your preferred defaults in AppDelegate each time the app starts.
Next Steps
Keyboard Management
Learn how IQKeyboardManager works internally
Subspecs
Understand the modular architecture