Skip to main content

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() or restorePosition()
  • 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
Subscribers receive notifications through the configuration completion handler:

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

The canRestoreContentOffset flag controls whether the scroll view’s content offset is restored when the keyboard dismisses.
  • Set to true for scroll views containing the text field
  • Set to false for the text view itself (when it’s scrollable)
This prevents scroll position “jumping” in complex layouts.

Global Settings

Configure IQKeyboardManager globally via the shared instance.

Enable/Disable

isEnabled defaults to false. You must explicitly enable IQKeyboardManager in your AppDelegate.

Keyboard Distance

Set the default distance between keyboard and text input:
Requirements:
  • Must be non-negative
  • Negative values log warnings

Layout Behavior

When true, calls setNeedsLayout() and layoutIfNeeded() on each frame update.

Class-Level Control

Disable keyboard management for specific view controller types:
Force enable for specific classes:
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:
Implementation:

Enable Mode

Control keyboard management per text input view:
Enable modes:
IQKeyboardManager evaluates enable state in this order:
  1. View-specific enable mode (.iq.enableMode)
    • .enabled → Always enabled
    • .disabled → Always disabled
    • .default → Continue to next check
  2. View controller class lists
    • If in disabledDistanceHandlingClasses → Disabled
    • If in enabledDistanceHandlingClasses → Enabled
    • Otherwise → Use global setting
  3. 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:
The library checks this when finding scrollable parents:

Ignore Content Inset Adjustment

Prevent IQKeyboardManager from modifying content insets:
Used when calculating scroll view adjustments:

Restore Content Offset

Control whether content offset is restored when keyboard dismisses:

Configuration Best Practices

1. Initialize Early

Enable IQKeyboardManager in AppDelegate:

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:
Only enable layoutIfNeededOnUpdate if you experience layout issues. It can impact performance with complex view hierarchies.

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 changes apply immediately:
Per-view settings use associated objects and persist with the view:
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