iOS Developer Library

Developer

UIKit Framework Reference UIPanGestureRecognizer Class Reference

Options
Deployment Target:

On This Page
Language:

UIPanGestureRecognizer

Conforms To


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 3.2 and later.

UIPanGestureRecognizer is a concrete subclass of UIGestureRecognizer that looks for panning (dragging) gestures. The user must be pressing one or more fingers on a view while they pan it. Clients implementing the action method for this gesture recognizer can ask it for the current translation and velocity of the gesture.

A panning gesture is continuous. It begins (UIGestureRecognizerStateBegan) when the minimum number of fingers allowed (minimumNumberOfTouches) has moved enough to be considered a pan. It changes (UIGestureRecognizerStateChanged) when a finger moves while at least the minimum number of fingers are pressed down. It ends (UIGestureRecognizerStateEnded) when all fingers are lifted.

Clients of this class can, in their action methods, query the UIPanGestureRecognizer object for the current translation of the gesture (translationInView:) and the velocity of the translation (velocityInView:). They can specify the view whose coordinate system should be used for the translation and velocity values. Clients may also reset the translation to a desired value.

  • The maximum number of fingers that can be touching the view for this gesture to be recognized.

    Declaration

    Swift

    var maximumNumberOfTouches: Int

    Objective-C

    @property(nonatomic) NSUInteger maximumNumberOfTouches

    Discussion

    The default value is NSUIntegerMax.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The minimum number of fingers that can be touching the view for this gesture to be recognized.

    Declaration

    Swift

    var minimumNumberOfTouches: Int

    Objective-C

    @property(nonatomic) NSUInteger minimumNumberOfTouches

    Discussion

    The default value is 1.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The translation of the pan gesture in the coordinate system of the specified view.

    Declaration

    Swift

    func translationInView(_ view: UIView) -> CGPoint

    Objective-C

    - (CGPoint)translationInView:(UIView *)view

    Parameters

    view

    The view in whose coordinate system the translation of the pan gesture should be computed. If you want to adjust a view's location to keep it under the user's finger, request the translation in that view's superview's coordinate system.

    Return Value

    A point identifying the new location of a view in the coordinate system of its designated superview.

    Discussion

    The x and y values report the total translation over time. They are not delta values from the last time that the translation was reported. Apply the translation value to the state of the view when the gesture is first recognized—do not concatenate the value each time the handler is called.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Sets the translation value in the coordinate system of the specified view.

    Declaration

    Swift

    func setTranslation(_ translation: CGPoint, inView view: UIView!)

    Objective-C

    - (void)setTranslation:(CGPoint)translation inView:(UIView *)view

    Parameters

    translation

    A point that identifies the new translation value.

    view

    A view in whose coordinate system the translation is to occur.

    Discussion

    Changing the translation value resets the velocity of the pan.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • The velocity of the pan gesture in the coordinate system of the specified view.

    Declaration

    Swift

    func velocityInView(_ view: UIView!) -> CGPoint

    Objective-C

    - (CGPoint)velocityInView:(UIView *)view

    Parameters

    view

    The view in whose coordinate system the velocity of the pan gesture is computed.

    Return Value

    The velocity of the pan gesture, which is expressed in points per second. The velocity is broken into horizontal and vertical components.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 3.2 and later.