Overview
IQKeyboardManager is the primary class in the IQKeyboardManager library. It provides automatic keyboard management by preventing the keyboard from covering UITextField and UITextView controls. The class implements a singleton pattern and handles all keyboard interactions seamlessly without requiring manual code integration.
All public APIs must be called from the main thread. The class is marked with
@MainActor to enforce this at compile time.Singleton Access
AppDelegate or @main entry point.
Basic Usage
Configuration Properties
Core Settings
Enables or disables keyboard distance management globally.When enabled, the manager automatically adjusts the view hierarchy to prevent the keyboard from covering active text input views. When disabled, all position adjustments are reverted.
The default distance (in points) between the keyboard and the active text input view.This global setting applies to all text inputs unless overridden using
view.iq.distanceFromKeyboard for specific views.Animation Settings
Determines whether to call
setNeedsLayout() and layoutIfNeeded() on the view controller’s view during frame updates.Enable this when using Auto Layout constraints that need to be recalculated during keyboard adjustments.Class-Level Configuration
An array of view controller classes for which keyboard distance handling should be disabled.When a view controller is of one of these types, keyboard distance handling is disabled regardless of the
isEnabled property. This takes precedence over enabledDistanceHandlingClasses.All classes must be subclasses of
UIViewController.An array of view controller classes that should have keyboard distance handling force-enabled.Within this scope, the global
isEnabled property is ignored. However, if a class appears in both disabledDistanceHandlingClasses and enabledDistanceHandlingClasses, it will be disabled.Public Methods
reloadLayoutIfNeeded()
Manually triggers a position adjustment for the active text input view.- After programmatically modifying view frames
- After adding or removing views from the hierarchy
- After changing Auto Layout constraints that affect the active text field’s position
- When orientation changes occur outside the normal notification flow
This method only has an effect when:
isEnabledistrue- A text input view is currently active
- The keyboard is visible
- The root configuration is ready
Internal Configuration
TheIQKeyboardManager class maintains an internal activeConfiguration property of type IQActiveConfiguration that tracks the current keyboard and text input state. This is used internally and is not exposed to public API consumers.
Thread Safety
All APIs are marked with@MainActor, ensuring they are always called on the main thread. Attempting to call these methods from a background thread will result in a compile-time error in Swift 6+ or a runtime assertion in earlier versions.
Availability
The class is marked with@available(iOSApplicationExtension, unavailable) because it relies on UIApplication APIs that are not available in app extensions.
See Also
- IQActiveConfiguration - Tracks active keyboard and text input state
- IQRootControllerConfiguration - Manages root view controller layout state
- IQScrollViewConfiguration - Handles scroll view adjustment state
- Configuration Guide - Comprehensive configuration options
- UIView Extensions - Per-view customization APIs