Overview
IQKeyboardManager uses a modular architecture that allows you to include only the features you need. When installed via CocoaPods, the library is split into multiple subspecs that can be included independently.When using Swift Package Manager (SPM), all modules are included by default. The subspec system is specific to CocoaPods installations.
Architecture Diagram
Default Installation
By default, all subspecs are included:- Core
- Appearance
- IQKeyboardToolbarManager
- IQKeyboardReturnManager
- IQTextView
- Resign
Core Subspecs
Core (Required)
The fundamental keyboard management functionality. Source Files:IQKeyboardManagerSwift/IQKeyboardManager/**/*.{swift}
Features:
- Main
IQKeyboardManagerclass - Position adjustment logic
- View hierarchy traversal
- Configuration system (IQActiveConfiguration, IQRootControllerConfiguration, IQScrollViewConfiguration)
- UIView extensions (
.iqnamespace) - ScrollView handling
- Internal utilities
IQKeyboardNotification- Keyboard event observingIQTextInputViewNotification- Text field/text view focus tracking
Appearance
Keyboard appearance customization functionality. Source Files:IQKeyboardManagerSwift/Appearance/**/*.{swift}
Features:
IQKeyboardAppearanceManager- Central appearance coordinatorIQKeyboardAppearanceConfiguration- Appearance settings storage- Automatic keyboard appearance matching
- Overrides UITextField/UITextView keyboard appearance
IQTextInputViewNotification
IQKeyboardToolbarManager
Toolbar with Previous/Next/Done buttons above the keyboard. Source Files:IQKeyboardManagerSwift/IQKeyboardToolbarManager/**/*.{swift}
Features:
- Automatic toolbar with navigation buttons
- Previous/Next navigation between text fields
- Done button to dismiss keyboard
- Customizable toolbar appearance
- Integration with IQKeyboardManager
IQKeyboardToolbarManager(external module)
Toolbar Manager Features
Toolbar Manager Features
The toolbar manager provides:
- Previous/Next buttons - Navigate between text fields in responder chain
- Done button - Dismiss keyboard
- Title label - Optional placeholder text display
- Customization - Tint colors, fonts, button items
- Automatic management - Enables/disables buttons based on responder chain
IQKeyboardReturnManager
Automatic keyboard return key handling. Source Files: Bridge to external module Features:- Automatic return key handling
- Move to next field on return key
- Submit form on last field
- Customizable return key types
- Integration with responder chain
IQKeyboardReturnManager(external module)
- Sets appropriate return key types (Next/Done)
- Moves to next field when return is tapped
- Dismisses keyboard on last field
IQTextView
Enhanced UITextView with placeholder support. Source Files: Bridge to external module Features:- Built-in placeholder support
- Matches UITextField placeholder behavior
- Customizable placeholder appearance
- Automatic placeholder hiding/showing
IQTextView(external module)
IQTextView is a standalone module that works independently of IQKeyboardManager but is commonly used together for enhanced text input functionality.
Resign
Keyboard dismissal by tapping outside text fields. Source Files:IQKeyboardManagerSwift/Resign/**/*.{swift}
Features:
IQKeyboardResignHandler- Manages tap-to-dismiss- Automatic gesture recognizer management
- Configurable dismiss behavior
- Integration with IQKeyboardManager
IQTextInputViewNotification
Selective Installation
Minimal Installation
Install only core keyboard management:- Position adjustment
- Keyboard distance handling
- Basic configuration
- No toolbar, no appearance, no resign
Core + Toolbar
Most common configuration for form-heavy apps:Core + Resign
For apps that want tap-to-dismiss without toolbar:Custom Combination
Mix and match based on needs:Subspec Dependencies
Dependency Tree
External Dependencies
IQKeyboardManager relies on these external modules: IQKeyboardNotification (v1.0.6+)- Observes keyboard show/hide/change notifications
- Provides animation synchronization
- Used by: Core
- Tracks text field/text view focus changes
- Monitors begin/end editing events
- Used by: Core, Appearance, Resign
- Complete toolbar implementation
- Button management and responder chain
- Used by: IQKeyboardToolbarManager subspec
- Return key handling logic
- Responder chain navigation
- Used by: IQKeyboardReturnManager subspec
- UITextView with placeholder
- Standalone text view enhancement
- Used by: IQTextView subspec
Podspec Configuration
Full Podspec Structure
Default Subspecs
Thedefault_subspecs array defines what’s included with:
Swift Package Manager
When using SPM, subspecs don’t apply. Install via Package.swift:Swift Package Manager doesn’t support the concept of subspecs. All modules are included as separate package products that you can import individually.
Choosing Subspecs
When to Use Each Subspec
| Subspec | Use When | Skip When |
|---|---|---|
| Core | Always (required) | Never |
| Appearance | You want automatic keyboard appearance matching | You manually set keyboard appearance |
| IQKeyboardToolbarManager | You have forms with multiple fields | Single field apps, custom navigation |
| IQKeyboardReturnManager | You want automatic return key handling | You handle return keys manually |
| IQTextView | You need UITextView with placeholders | You use only UITextField |
| Resign | You want tap-outside-to-dismiss | You dismiss keyboard programmatically |
Optimization Strategies
Minimize Binary SizeMigration from Objective-C
If migrating from the Objective-C version (IQKeyboardManager), note:
- Different pod name:
IQKeyboardManagerSwiftvsIQKeyboardManager - Subspec structure: Swift version has modular subspecs
- Import statements:
import IQKeyboardManagerSwift
Best Practices
1. Start with Default Installation
Begin with full installation during development:2. Profile and Optimize
After development, profile your app and remove unused subspecs:3. Document Subspec Choices
Add comments explaining why subspecs were excluded:4. Keep Dependencies Updated
Regularly update external dependencies:5. Test Subspec Combinations
Test your specific subspec combination thoroughly:Troubleshooting
Missing Functionality
Problem: Feature not available after selective installation Solution: Check if the feature is in an excluded subspecDuplicate Symbols
Problem: Linker errors with duplicate symbols Solution: Don’t mix default and selective installationImport Errors
Problem: Cannot import subspec-specific classes Solution: Always import the main moduleNext Steps
Installation
Learn how to install IQKeyboardManager
Configuration
Configure IQKeyboardManager for your app