Class: UIResponder
Overview
The UIResponder class defines an interface for objects that respond to and handle events. It is the superclass of UIApplication, UIView and its subclasses (which include UIWindow). Instances of these classes are sometimes referred to as responder objects or, simply, responders.
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- inputAccessoryView
readonly
The custom accessory view to display when the object becomes the first responder.
-
- inputView
readonly
The custom input view to display when the object becomes the first responder.
-
- undoManager
readonly
Returns the nearest shared undo manager in the responder chain.
Instance Method Summary (collapse)
-
- becomeFirstResponder
Notifies the receiver that it is about to become first responder in its window.
-
- canBecomeFirstResponder
Returns a Boolean value indicating whether the receiver can become first responder.
-
- canPerformAction:withSender:
Requests the receiving responder to enable or disable the specified command in the user interface.
-
- canResignFirstResponder
Returns a Boolean value indicating whether the receiver is willing to relinquish first-responder status.
-
- isFirstResponder
Returns a Boolean value indicating whether the receiver is the first responder.
-
- motionBegan:withEvent:
Tells the receiver that a motion event has begun.
-
- motionCancelled:withEvent:
Tells the receiver that a motion event has been cancelled.
-
- motionEnded:withEvent:
Tells the receiver that a motion event has ended.
-
- nextResponder
Returns the receiver’s next responder, or nil if it has none.
-
- reloadInputViews
Updates the custom input and accessory views when the object is the first responder.
-
- remoteControlReceivedWithEvent:
Sent to the receiver when a remote-control event is received.
-
- resignFirstResponder
Notifies the receiver that it has been asked to relinquish its status as first responder in its window.
-
- touchesBegan:withEvent:
Tells the receiver when one or more fingers touch down in a view or window.
-
- touchesCancelled:withEvent:
Sent to the receiver when a system event (such as a low-memory warning) cancels a touch event.
-
- touchesEnded:withEvent:
Tells the receiver when one or more fingers are raised from a view or window.
-
- touchesMoved:withEvent:
Tells the receiver when one or more fingers associated with an event move within a view or window.
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Instance Attribute Details
- (UIView) inputAccessoryView (readonly)
The custom accessory view to display when the object becomes the first responder. (read-only) The default value of this property is nil. Subclasses that want to attach custom controls to either a system-supplied input view (such as the keyboard) or a custom input view (one you provide in the inputView property) should redeclare this property as readwrite and use it to manage their custom accessory view. When the receiver subsequently becomes the first responder, the responder infrastructure attaches the view to the appropriate input view before displaying it.This property is typically used to attach an accessory view to the system-supplied keyboard that is presented for UITextField and UITextView objects.
- (UIView) inputView (readonly)
The custom input view to display when the object becomes the first responder. (read-only) The value of this property is nil. Responder objects that require a custom view to gather input from the user should redeclare this property as readwrite and use it to manage their custom input view. When the receiver subsequently becomes the first responder, the responder infrastructure presents the specified input view automatically. Similarly, when the view resigns its first responder status, the responder infrastructure automatically dismisses the specified view. This property is typically used to replace the system-supplied keyboard that is presented for UITextField and UITextView objects.
- (NSUndoManager) undoManager (readonly)
Returns the nearest shared undo manager in the responder chain. By default, every window of an application has an undo manager: a shared object for managing undo and redo operations. However, the class of any object in the responder chain can have their own custom undo manager. (For example, instances of UITextField have their own undo manager that is cleared when the text field resigns first-responder status.) When you request an undo manager, the request goes up the responder chain and the UIWindowobject returns a usable instance. You may add undo managers to your view controllers to perform undo and redo operations local to the managed view.
Instance Method Details
- (Boolean) becomeFirstResponder
Notifies the receiver that it is about to become first responder in its window. Subclasses can override this method to update state or perform some action such as highlighting the selection. A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.You may call this method to make a responder object such as a view the first responder. However, you should only call it on that view if it is part of a view hierarchy. If the view’s window property holds a UIWindow object, it has been installed in a view hierarchy; if it returns nil, the view is detached from any hierarchy.
- (Boolean) canBecomeFirstResponder
Returns a Boolean value indicating whether the receiver can become first responder. Returns NO by default. If a responder object returns YES from this method, it becomes the first responder and can receive touch events and action messages. Subclasses must override this method to be able to become first responder.You must not send this message to a view that is not currently attached to the view hierarchy. The result is undefined.
- (Boolean) canPerformAction(action, withSender:sender)
Requests the receiving responder to enable or disable the specified command in the user interface. This default implementation of this method returns YES if the responder class implements the requested action and calls the next responder if it does not. Subclasses may override this method to enable menu commands based on the current state; for example, you would enable the Copy command if there is a selection or disable the Paste command if the pasteboard did not contain data with the correct pasteboard representation type. If no responder in the responder chain returns YES, the menu command is disabled. Note that if your class returns NO for a command, another responder further up the responder chain may still return YES, enabling the command.This method might be called more than once for the same action but with a different sender each time. You should be prepared for any kind of sender including nil. For information on the editing menu, see the description of the UIMenuController class.
- (Boolean) canResignFirstResponder
Returns a Boolean value indicating whether the receiver is willing to relinquish first-responder status. Returns YES by default. As an example, a text field in the middle of editing might want to implement this method to return NO to keep itself active during editing.
- (Boolean) isFirstResponder
Returns a Boolean value indicating whether the receiver is the first responder.
- (Object) motionBegan(motion, withEvent:event)
Tells the receiver that a motion event has begun. iOS informs the first responder only when a motion event starts and when it ends; for example, it doesn’t report individual shakes. The receiving object must be the first responder to receive motion events.The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain.
- (Object) motionCancelled(motion, withEvent:event)
Tells the receiver that a motion event has been cancelled. This method is invoked when the Cocoa Touch framework receives an interruption requiring cancellation of the motion event. This interruption is something that might cause the application to be no longer active or the view to be removed from the window. The method can also be invoked if the shaking goes on too long. All responders that handle motion events should implement this method; in it they should clean up any state information that was established in the motionBegan:withEvent: implementation.The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain.
- (Object) motionEnded(motion, withEvent:event)
Tells the receiver that a motion event has ended. iOS informs the responder only when a motion event starts and when it ends; for example, it doesn’t report individual shakes. The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain.
- (UIResponder) nextResponder
Returns the receiver’s next responder, or nil if it has none. The UIResponder class does not store or set the next responder automatically, instead returning nil by default. Subclasses must override this method to set the next responder. UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t); UIViewController implements the method by returning its view’s superview; UIWindow returns the application object, and UIApplication returns nil.
- (Object) reloadInputViews
Updates the custom input and accessory views when the object is the first responder. You can use this method to refresh the custom input view or input accessory view associated with the current object when it is the first responder. The views are replaced immediately—that is, without animating them into place. If the current object is not the first responder, this method has no effect.
- (Object) remoteControlReceivedWithEvent(event)
Sent to the receiver when a remote-control event is received. Remote-control events originate as commands from external accessories, including headsets. An application responds to these commands by controlling audio or video media presented to the user. The receiving responder object should examine the subtype of event to determine the intended command—for example, play (UIEventSubtypeRemoteControlPlay)—and then proceed accordingly.To allow delivery of remote-control events, you must call the beginReceivingRemoteControlEvents method of UIApplication; to turn off delivery of remote-control events, call endReceivingRemoteControlEvents.
- (Boolean) resignFirstResponder
Notifies the receiver that it has been asked to relinquish its status as first responder in its window. The default implementation returns YES, resigning first responder status. Subclasses can override this method to update state or perform some action such as unhighlighting the selection, or to return NO, refusing to relinquish first responder status. If you override this method, you must call super (the superclass implementation) at some point in your code.
- (Object) touchesBegan(touches, withEvent:event)
Tells the receiver when one or more fingers touch down in a view or window. The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example, If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the corresponding view instance to YES.
- (Object) touchesCancelled(touches, withEvent:event)
Sent to the receiver when a system event (such as a low-memory warning) cancels a touch event. This method is invoked when the Cocoa Touch framework receives a system interruption requiring cancellation of the touch event; for this, it generates a UITouch object with a phase of UITouchPhaseCancel. The interruption is something that might cause the application to be no longer active or the view to be removed from the window When an object receives a touchesCancelled:withEvent: message it should clean up any state information that was established in its touchesBegan:withEvent: implementation.The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example, If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.
- (Object) touchesEnded(touches, withEvent:event)
Tells the receiver when one or more fingers are raised from a view or window. The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example, When an object receives a touchesEnded:withEvent: message it should clean up any state information that was established in its touchesBegan:withEvent: implementation.Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the corresponding view instance to YES.If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.
- (Object) touchesMoved(touches, withEvent:event)
Tells the receiver when one or more fingers associated with an event move within a view or window. The default implementation of this method does nothing. However immediate UIKit subclasses of UIResponder, particularly UIView, forward the message up the responder chain. To forward the message to the next responder, send the message to super (the superclass implementation); do not send the message directly to the next responder. For example, Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the corresponding view instance to YES.If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empty) implementations.