Skip to main content

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

The shared instance is available throughout your application and should be configured once, typically in your AppDelegate or @main entry point.

Basic Usage

Configuration Properties

Core Settings

Bool
default:"false"
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.
CGFloat
default:"10.0"
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.
The value must be non-negative. Negative values will be logged as warnings.

Animation Settings

Bool
default:"false"
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

[UIViewController.Type]
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.
[UIViewController.Type]
default:"[]"
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.
Call this method when you’ve made external changes to the view hierarchy that might affect keyboard positioning (e.g., programmatically changing view frames, adding/removing views, changing constraints). When to Call:
  • 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
Example:
This method only has an effect when:
  • isEnabled is true
  • A text input view is currently active
  • The keyboard is visible
  • The root configuration is ready
It is safe to call even when these conditions are not met - the method will simply return early.

Internal Configuration

The IQKeyboardManager 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

This class is unavailable in iOS App Extensions.
The class is marked with @available(iOSApplicationExtension, unavailable) because it relies on UIApplication APIs that are not available in app extensions.

See Also