First Responder is the UIResponder object in iOS that receives touch events, key presses, shake gestures, and menu commands first. At any given moment, only one object in the application can be the first responder. Assignment occurs automatically (when a UITextField gains focus) or programmatically via the becomeFirstResponder method. According to Apple Developer Documentation (2026), an object can become first responder only if its canBecomeFirstResponder method returns true, making this mechanism explicit and controllable.
Key Takeaways
First Responder is the UIResponder object that currently receives input events in an iOS application. The system directs all touch events, key presses, motion events (device shaking), and action messages (e.g., invoking a context menu) to this object.
The first responder concept is the first link in the Responder Chain. If the first responder does not handle a received event, it is automatically passed to the next object in the chain. This ensures that an event is not lost but is sequentially offered to all potential handlers in the hierarchy.
According to Apple, the first responder status is closely tied to UIResponder and its methods canBecomeFirstResponder and becomeFirstResponder. By default, UIView returns true only for certain subclasses — UITextField, UITextView, UISearchBar. Other views, including plain UIView, return false, preventing accidental assignment.
Assignment of first responder can happen in two ways: automatically, when the user touches a UITextField (the system calls becomeFirstResponder internally), or programmatically, when the developer explicitly calls the becomeFirstResponder method on any UIResponder object.
Before assignment, iOS checks canBecomeFirstResponder. If the method returns false, the becomeFirstResponder call is ignored, and the object does not become first responder. This is a protective mechanism that prevents assigning objects that are not ready to handle events — for example, hidden or disabled interface elements.
class CustomTextField: UITextField {
override var canBecomeFirstResponder: Bool {
return super.canBecomeFirstResponder
}
}
// Programmatic assignment
textField.becomeFirstResponder()
// Check if first responder
if textField.isFirstResponder {
print("TextField is now first responder")
}
When a new first responder is assigned, iOS automatically calls resignFirstResponder on the previous one. This guarantees there is always only one object with first responder status in the system. If the new object cannot become first responder (canBecomeFirstResponder = false), the old one retains its status.
The iOS keyboard appears on screen precisely because of the first responder mechanism. When a UITextField or UITextView becomes first responder, the system automatically displays the keyboard associated with the current keyboardType of that field. When first responder resigns, the keyboard hides.
This behavior is a key UX mechanism in iOS: the user touches an input field — the keyboard appears; presses Return or touches another field — the keyboard switches or hides. The developer can control this through UIResponder methods, as well as through inputView and inputAccessoryView to replace the standard keyboard with a custom one.
Input Accessory View is an additional panel above the keyboard that is also tied to the first responder. For example, a panel with Next, Previous, Done buttons for navigating between input fields. It appears and hides together with the keyboard, synchronizing with the first responder status.
| Event | First Responder Status | Keyboard |
|---|---|---|
| Touching UITextField | Becomes first responder | Appears |
| Pressing Return | Stays or resigns | Stays or hides |
| Touching another field | Moves to the new field | Switches |
| Calling resignFirstResponder | Removed | Hides |
| App entering background | Automatically resigns | Hides |
ResignFirstResponder is a UIResponder method that removes the first responder status from an object. After the call, the object stops receiving input events, and the keyboard (if it was active) hides. The method returns a Bool — true if the resign was successful.
Developers often call resignFirstResponder in response to pressing the Done button, tapping an empty area of the screen (view.endEditing), or when leaving the screen. view.endEditing(true) is a convenient way to resign for all child text fields at once: it traverses the entire view hierarchy and calls resignFirstResponder on the current first responder.
// Resign on Done button tap
@objc func doneButtonTapped() {
textField.resignFirstResponder()
}
// Resign on empty area tap
override func touchesBegan(
_ touches: Set<UITouch>,
with event: UIEvent?
) {
view.endEditing(true)
}
// Resign for all form fields
func validateAndSubmit() {
view.endEditing(true)
// Form submission logic
}
There are situations where resignFirstResponder may return false. This happens if the object has overridden the method and explicitly prevented status removal. For example, a text field in the process of validation may temporarily block resign to prevent data loss. In such cases, you must wait for validation to complete and only then forcibly resign.
UIResponder provides the isFirstResponder property (read-only), which returns true if the given object is currently the first responder. This is useful for conditional logic — for example, to avoid performing an action if a text field is focused and the user is entering data.
iOS does not provide a built-in API for obtaining the current first responder on an application-wide scale. Developers achieve this by traversing the view hierarchy using the UIResponder method. Apple recommends a weak reference to the first responder, which can be updated via KVO or delegates.
// Extension to find first responder
extension UIView {
var firstResponder: UIResponder? {
guard isFirstResponder else {
return subviews.compactMap { $0.firstResponder }.first
}
return self
}
}
// Usage
if let current = view.firstResponder {
print("Current first responder: \(current)")
}
For tracking changes to the first responder, you can subscribe to UIResponder.keyboardWillShowNotification and UIResponder.keyboardWillHideNotification — they indirectly indicate that some text object has become or stopped being the first responder. However, there is no direct subscription for isFirstResponder changes; KVO or custom delegates are used instead.
Custom views can become first responder if they override canBecomeFirstResponder and return true. This is necessary for components that need to receive keyboard or physical button events — for example, custom game controllers or code editors based on UITextView.
When creating a custom first responder, it is important to keep accessibility in mind: VoiceOver and Switch Control rely on correct first responder assignment for navigation. If a custom view becomes first responder, it must correctly implement the UIAccessibility protocol and report its status to assistive technologies.
For custom input (e.g., a barcode scanner or digital keypad), override the inputView property — return a custom UIView that will be displayed instead of the standard keyboard when this view is the first responder. Similarly, inputAccessoryView adds a panel above the keyboard.
Frequently Asked Questions
First Responder is the UIResponder object that currently receives input events (touch, keys, accelerometer). It is assigned via becomeFirstResponder and must return true from canBecomeFirstResponder. Only one object can be first responder in an application.
Call textField.becomeFirstResponder() programmatically, for example, in viewDidAppear. Make sure the textField is not hidden, userInteractionEnabled = true, and isEnabled = true. If the field is inside a UITableView or UICollectionView, ensure the cell is visible on screen.
Add a UITapGestureRecognizer to the main view and call view.endEditing(true) in its handler. This will automatically find the current first responder and call resignFirstResponder. Alternatively, override touchesBegan in UIViewController with a call to endEditing.
becomeFirstResponder returns false if canBecomeFirstResponder returns false, the view is hidden, not in the window hierarchy, or userInteractionEnabled = false. Also check that the view is added to the window — a view that is not on screen will not respond to becomeFirstResponder.
iOS does not provide a global API for this. Use a recursive traversal of the view hierarchy through a UIView extension that checks isFirstResponder on each subview. An alternative is to store a weak reference to the last first responder in AppDelegate and update it through UITextField delegates.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also