Skip to main content

Overview

The Resign subspec enables “tap-to-dismiss” functionality, allowing users to dismiss the keyboard by tapping anywhere outside of the active text field. This provides an intuitive way to close the keyboard without requiring a Done button.

Installation

CocoaPods

Podfile

Swift Package Manager

The Resign functionality is included in the main package:

Basic Setup

1

Import the library

AppDelegate.swift
2

Enable resign on touch outside

AppDelegate.swift
3

Test tap-to-dismiss

Run your app, tap on a text field to show the keyboard, then tap anywhere outside the text field to dismiss it.

How It Works

When enabled, IQKeyboardManager:
  1. Adds a tap gesture recognizer to the window
  2. Detects taps outside active text fields
  3. Dismisses the keyboard when a tap is detected
  4. Ignores taps on interactive controls (buttons, switches, etc.)
  5. Handles conflicts with existing gestures

Configuration

Enable/Disable

Programmatic Dismissal

Manually dismiss the keyboard:
ViewController.swift

Class-Level Control

Disable for Specific View Controllers

Prevent tap-to-dismiss for specific view controllers:
AppDelegate.swift
By default, UIAlertController and UIInputViewController are in the disabled list.

Force Enable for Specific Classes

AppDelegate.swift
If a class appears in both disabledTouchResignedClasses and enabledTouchResignedClasses, the disabled list takes precedence.

Ignore Specific View Types

Prevent tap-to-dismiss when tapping on specific view types:
AppDelegate.swift
By default, taps on UIControl (buttons, switches, etc.) and UINavigationBar won’t dismiss the keyboard, allowing users to interact with these elements while the keyboard is visible.

Gesture Recognizer Access

Access the tap gesture recognizer to handle conflicts:
ViewController.swift

Complete Example

ViewController.swift

Advanced Scenarios

Conditional Resign

Enable resign on touch only for specific scenarios:
ViewController.swift

Per-View Controller Control

ViewController.swift

Custom Gesture Handling

ViewController.swift

UIScrollView Interaction

Handling tap-to-dismiss with scroll views:
ViewController.swift

Resign vs Done Button

Tap-to-Dismiss

Best for:
  • Single text field screens
  • Simple forms
  • Modal text input
  • Quick edits
Advantages:
  • Natural gesture
  • No UI required
  • Works anywhere

Done/Toolbar Button

Best for:
  • Multi-field forms
  • Guided input flows
  • Complex forms
  • Required validation
Advantages:
  • Clear action
  • More discoverable
  • Can trigger validation
You can use both tap-to-dismiss and toolbar buttons together for maximum flexibility.

Best Practices

Tap-to-dismiss is intuitive and should be enabled for most screens. Only disable it when you have specific interaction requirements.
The default configuration ignores taps on buttons and controls, which is usually what you want. Users can tap buttons without dismissing the keyboard.
If your app uses custom gestures, test thoroughly to ensure they don’t conflict with the resign gesture.
Consider adding visual feedback when the keyboard dismisses to help users understand the interaction.

Troubleshooting

  • Verify resignOnTouchOutside is set to true
  • Check if the view controller is in disabledTouchResignedClasses
  • Ensure no other gesture is blocking the tap gesture
  • Check if a custom gesture has higher priority
  • Verify UIControl is in touchResignedGestureIgnoreClasses
  • Check if button’s isUserInteractionEnabled is true
  • Ensure button is not hidden or has zero alpha
  • Use require(toFail:) to manage gesture priority
  • Implement UIGestureRecognizerDelegate for custom control
  • Access IQKeyboardManager.shared.resignGesture to handle conflicts
  • Add UITableViewCell to touchResignedGestureIgnoreClasses
  • Or implement tableView(_:didSelectRowAt:) to dismiss manually
Bool
default:"false"
Enable tap-to-dismiss keyboard functionality
UITapGestureRecognizer
default:"UITapGestureRecognizer()"
The tap gesture recognizer used for dismiss functionality. Read-only, exposed for handling gesture dependencies.
[UIViewController.Type]
View controller classes where tap-to-dismiss is disabled
[UIViewController.Type]
default:"[]"
View controller classes where tap-to-dismiss is force-enabled
[UIView.Type]
default:"[UIControl.self, UINavigationBar.self]"
View classes that won’t trigger tap-to-dismiss when tapped

Next Steps

Advanced Configuration

Fine-tune keyboard behavior

Toolbar Management

Add navigation buttons to keyboard

Debugging

Troubleshoot resign issues

API Reference

Full API documentation