Class: UIGestureRecognizer
Overview
UIGestureRecognizer is an abstract base class for concrete gesture-recognizer classes. A gesture-recognizer object (or, simply, a gesture recognizer) decouples the logic for recognizing a gesture and acting on that recognition. When one of these objects recognizes a common gesture or, in some cases, a change in the gesture, it sends an action message to each designated target object.
Direct Known Subclasses
UILongPressGestureRecognizer, UIPanGestureRecognizer, UIPinchGestureRecognizer, UIRotationGestureRecognizer, UISwipeGestureRecognizer, UITapGestureRecognizer
Instance Attribute Summary (collapse)
-
- cancelsTouchesInView
A Boolean value affecting whether touches are delivered to a view when a gesture is recognized.
-
- delaysTouchesBegan
A Boolean value determining whether the receiver delays sending touches in a begin phase to its view.
-
- delaysTouchesEnded
A Boolean value determining whether the receiver delays sending touches in a end phase to its view.
-
- delegate
The delegate of the gesture recognizer.
-
- enabled
A Boolean property that indicates whether the gesture recognizer is enabled.
-
- state
readonly
The current state of the gesture recognizer.
-
- view
readonly
The view the gesture recognizer is attached to.
Instance Method Summary (collapse)
-
- addTarget:action:
Adds a target and an action to a gesture-recognizer object.
-
- canBePreventedByGestureRecognizer:
Overridden to indicate that the specified gesture recognizer can prevent the receiver from recognizing a gesture.
-
- canPreventGestureRecognizer:
Overridden to indicate that the receiver can prevent the specified gesture recognizer from recognizing its gesture.
-
- ignoreTouch:forEvent:
Tells the gesture recognizer to ignore a specific touch of the given event.
-
- initWithTarget:action:
Initializes an allocated gesture-recognizer object with a target and an action selector.
-
- locationInView:
Returns the point computed as the location in a given view of the gesture represented by the receiver.
-
- locationOfTouch:inView:
Returns the location of one of the gesture’s touches in the local coordinate system of a given view.
-
- numberOfTouches
Returns the number of touches involved in the gesture represented by the receiver.
-
- removeTarget:action:
Removes a target and an action from a gesture-recognizer object.
-
- requireGestureRecognizerToFail:
Creates a dependency relationship between the receiver and another gesture recognizer.
-
- reset
Overridden to reset internal state when a gesture is recognized.
-
- touchesBegan:withEvent:
Sent to the receiver when one or more fingers touch down in the associated view.
-
- touchesCancelled:withEvent:
Sent to the receiver when a system event (such as a low-memory warning) cancels a touch event.
-
- touchesEnded:withEvent:
Sent to the receiver when one or more fingers lift from the associated view.
-
- touchesMoved:withEvent:
Sent to the receiver when one or more fingers move in the associated view.
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
- (Boolean) cancelsTouchesInView
A Boolean value affecting whether touches are delivered to a view when a gesture is recognized. When this property is YES (the default) and the receiver recognizes its gesture, the touches of that gesture that are pending are not delivered to the view and previously delivered touches are cancelled through a touchesCancelled:withEvent: message sent to the view. If a gesture recognizer doesn’t recognize its gesture or if the value of this property is NO, the view receives all touches in the multi-touch sequence.
- (Boolean) delaysTouchesBegan
A Boolean value determining whether the receiver delays sending touches in a begin phase to its view. When the value of this property is NO (the default), views analyze touch events in UITouchPhaseBegan and UITouchPhaseMoved in parallel with the receiver. When the value of the property is YES, the window suspends delivery of touch objects in the UITouchPhaseBegan phase to the view. If the gesture recognizer subsequently recognizes its gesture, these touch objects are discarded. If the gesture recognizer, however, does not recognize its gesture, the window delivers these objects to the view in a touchesBegan:withEvent: message (and possibly a follow-up touchesMoved:withEvent: message to inform it of the touches’ current locations). Set this property to YES to prevent views from processing any touches in the UITouchPhaseBegan phase that may be recognized as part of this gesture.
- (Boolean) delaysTouchesEnded
A Boolean value determining whether the receiver delays sending touches in a end phase to its view. When the value of this property is YES (the default) and the receiver is analyzing touch events, the window suspends delivery of touch objects in the UITouchPhaseEnded phase to the attached view. If the gesture recognizer subsequently recognizes its gesture, these touch objects are cancelled (via a touchesCancelled:withEvent: message). If the gesture recognizer does not recognize its gesture, the window delivers these objects in an invocation of the view’s touchesEnded:withEvent: method. Set this property to NO to have touch objects in the UITouchPhaseEnded delivered to the view while the gesture recognizer is analyzing the same touches.
- (Object) delegate
The delegate of the gesture recognizer. The gesture recognizer maintains a weak reference to its delegate. The delegate must adopt the UIGestureRecognizerDelegate protocol and implement one or more of its methods.
- (Boolean) enabled
A Boolean property that indicates whether the gesture recognizer is enabled. Disables a gesture recognizers so it does not receive touches. The default value is YES. If you change this property to NO while a gesture recognizer is currently recognizing a gesture, the gesture recognizer transitions to a cancelled state.
- (UIGestureRecognizerState) state (readonly)
The current state of the gesture recognizer. (read-only) The possible states a gesture recognizer can be in are represented by the constants of type UIGestureRecognizerState. Some of these states are not applicable to discrete gestures. The read-only version of the state property is intended for clients of a gesture-recognizer class and not subclasses.
Instance Method Details
- (Object) addTarget(target, action:action)
Adds a target and an action to a gesture-recognizer object. You may call this method multiple times to specify multiple target-action pairs. However, if you request to add a target-action pair that has already been added, then the request is ignored.
- (Boolean) canBePreventedByGestureRecognizer(preventingGestureRecognizer)
Overridden to indicate that the specified gesture recognizer can prevent the receiver from recognizing a gesture. Overriding these methods enables the same behavior as implementing the UIGestureRecognizerDelegate methods gestureRecognizerShouldBegin: and gestureRecognizer:shouldReceiveTouch:. However, by overriding them, subclasses can define class-wide prevention rules. For example, a UITapGestureRecognizer object never prevents another UITapGestureRecognizer object with a higher tap count.
- (Boolean) canPreventGestureRecognizer(preventedGestureRecognizer)
Overridden to indicate that the receiver can prevent the specified gesture recognizer from recognizing its gesture. Overriding these methods enables the same behavior as implementing the UIGestureRecognizerDelegate methods gestureRecognizerShouldBegin: and gestureRecognizer:shouldReceiveTouch:. However, by overriding them, subclasses can define class-wide prevention rules. For example, a UITapGestureRecognizer object never prevents another UITapGestureRecognizer object with a higher tap count.
- (Object) ignoreTouch(touch, forEvent:event)
Tells the gesture recognizer to ignore a specific touch of the given event. If a touch isn't part of this gesture you may pass it to this method, causing it to be ignored. UIGestureRecognizer does not cancel ignored touches on the associated view even if cancelsTouchesInView is YES. This method is intended to be called, not overridden.
- (Object) initWithTarget(target, action:action)
Initializes an allocated gesture-recognizer object with a target and an action selector. This method is the designated initializer. After creating the gesture recognizer, you may associate other target-action pairs with it by calling addTarget:action:.
- (CGPoint) locationInView(view)
Returns the point computed as the location in a given view of the gesture represented by the receiver. The returned value is a generic single-point location for the gesture computed by the UIKit framework. It is usually the centroid of the touches involved in the gesture. For objects of the UISwipeGestureRecognizer and UITapGestureRecognizer classes, the location returned by this method has a significance special to the gesture. This significance is documented in the reference for those classes.
- (CGPoint) locationOfTouch(touchIndex, inView:view)
Returns the location of one of the gesture’s touches in the local coordinate system of a given view.
- (Integer) numberOfTouches
Returns the number of touches involved in the gesture represented by the receiver. Using the value returned by this method in a loop, you can ask for the location of individual touches using the locationOfTouch:inView: method.
- (Object) removeTarget(target, action:action)
Removes a target and an action from a gesture-recognizer object. Calling this method removes the specified target-action pair. Passing nil for target matches all targets and passing NULL for action matches all actions.
- (Object) requireGestureRecognizerToFail(otherGestureRecognizer)
Creates a dependency relationship between the receiver and another gesture recognizer. This method creates a relationship with another gesture recognizer that delays the receiver’s transition out of UIGestureRecognizerStatePossible. The state that the receiver transitions to depends on what happens with otherGestureRecognizer: If otherGestureRecognizer transitions to UIGestureRecognizerStateFailed, the receiver transitions to its normal next state.if otherGestureRecognizer transitions to UIGestureRecognizerStateRecognized or UIGestureRecognizerStateBegan, the receiver transitions to UIGestureRecognizerStateFailed.An example where this method might be called is when you want a single-tap gesture require that a double-tap gesture fail.
- (Object) reset
Overridden to reset internal state when a gesture is recognized. The runtime calls this method after the gesture-recognizer state has been set to UIGestureRecognizerStateEnded or UIGestureRecognizerStateRecognized. Subclasses should reset any internal state in preparation for a new attempt at gesture recognition. After this method is called, the runtime ignores all remaining active touches; that is, the gesture recognizer receives no further updates for touches that have begun but haven't ended.
- (Object) touchesBegan(touches, withEvent:event)
Sent to the receiver when one or more fingers touch down in the associated view. This method has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseBegan phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.If the gesture recognizer is interpreting a continuous gesture, it should set its state to UIGestureRecognizerStateBegan upon receiving this message. If at any point in its handling of the touch objects the gesture recognizer determines that the multi-touch event sequence is not its gesture, it should set it state to UIGestureRecognizerStateCancelled.Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the attached 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 has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseCancelled phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.Upon receiving this message, the gesture recognizer for a continuous gesture should set its state to UIGestureRecognizerStateCancelled; a gesture recognizer for a discrete gesture should set its state to UIGestureRecognizerStateFailed.
- (Object) touchesEnded(touches, withEvent:event)
Sent to the receiver when one or more fingers lift from the associated view. This method has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseEnded phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.If the gesture recognizer is interpreting a continuous gesture, it should set its state to UIGestureRecognizerStateEnded upon receiving this message. If it is interpreting a discrete gesture, it should set its state to UIGestureRecognizerStateRecognized. If at any point in its handling of the touch objects the gesture recognizer determines that the multi-touch event sequence is not its gesture, it should set it state to UIGestureRecognizerStateCancelled.Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the attached view instance to YES.
- (Object) touchesMoved(touches, withEvent:event)
Sent to the receiver when one or more fingers move in the associated view. This method has the same exact signature as the corresponding one declared by UIResponder. Through this method a gesture recognizer receives touch objects (in their UITouchPhaseMoved phase) before the view attached to the gesture recognizer receives them. UIGestureRecognizer objects are not in the responder chain, yet observe touches hit-tested to their view and their view's subviews. After observation, the delivery of touch objects to the attached view, or their disposition otherwise, is affected by the cancelsTouchesInView, delaysTouchesBegan, and delaysTouchesEnded properties.If the gesture recognizer is interpreting a continuous gesture, it should set its state to UIGestureRecognizerStateChanged upon receiving this message. If at any point in its handling of the touch objects the gesture recognizer determines that the multi-touch event sequence is not its gesture, it should set it state to UIGestureRecognizerStateCancelled .Multiple touches are disabled by default. In order to receive multiple touch events you must set the a multipleTouchEnabled property of the attached view instance to YES.