iOS Developer Library

Developer

UIKit Framework Reference UITouch Class Reference

Options
Deployment Target:

On This Page
Language:

UITouch

A UITouch object represents the presence or movement of a finger on the screen for a particular event. You access UITouch objects through UIEvent objects passed into responder objects for event handling. More...

Inheritance


Conforms To


Import Statement


import UIKit @import UIKit;

Availability


Available in iOS 2.0 and later.
  • Returns the current location of the receiver in the coordinate system of the given view.

    Declaration

    Swift

    func locationInView(_ view: UIView?) -> CGPoint

    Objective-C

    - (CGPoint)locationInView:(UIView *)view

    Parameters

    view

    The view object in whose coordinate system you want the touch located. A custom view that is handling the touch may specify self to get the touch location in its own coordinate system. Pass nil to get the touch location in the window’s coordinates.

    Return Value

    A point specifying the location of the receiver in view.

    Discussion

    This method returns the current location of a UITouch object in the coordinate system of the specified view. Because the touch object might have been forwarded to a view from another view, this method performs any necessary conversion of the touch location to the coordinate system of the specified view.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Returns the previous location of the receiver in the coordinate system of the given view.

    Declaration

    Swift

    func previousLocationInView(_ view: UIView?) -> CGPoint

    Objective-C

    - (CGPoint)previousLocationInView:(UIView *)view

    Parameters

    view

    The view object in whose coordinate system you want the touch located. A custom view that is handling the touch may specify self to get the touch location in its own coordinate system. Pass nil to get the touch location in the window’s coordinates.

    Return Value

    This method returns the previous location of a UITouch object in the coordinate system of the specified view. Because the touch object might have been forwarded to a view from another view, this method performs any necessary conversion of the touch location to the coordinate system of the specified view.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • view view Property

    The view in which the touch initially occurred. (read-only)

    Declaration

    Swift

    var view: UIView { get }

    Objective-C

    @property(nonatomic, readonly, retain) UIView *view

    Discussion

    The value of the property is the view object in which the touch originally occurred. This object might not be the view the touch is currently in.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    window

  • window window Property

    The window in which the touch initially occurred. (read-only)

    Declaration

    Swift

    var window: UIWindow { get }

    Objective-C

    @property(nonatomic, readonly, retain) UIWindow *window

    Discussion

    The value of the property is the window object in which the touch originally occurred. This object might not be the window the touch is currently in.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    view

  • The radius (in points) of the touch. (read-only)

    Declaration

    Swift

    var majorRadius: CGFloat { get }

    Objective-C

    @property(nonatomic, readonly) CGFloat majorRadius

    Discussion

    Use the value in this property to determine the size of the touch that was reported by the hardware. This value is an approximation of the size and can vary by the amount specified in the majorRadiusTolerance property.

    Import Statement

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • The tolerance (in points) of the touch’s radius. (read-only)

    Declaration

    Swift

    var majorRadiusTolerance: CGFloat { get }

    Objective-C

    @property(nonatomic, readonly) CGFloat majorRadiusTolerance

    Discussion

    This value determines the accuracy of the value in the majorRadius property. Add this value to the radius to get the maximum touch radius. Subtract the value to get the minimum touch radius.

    Import Statement

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • tapCount tapCount Property

    The number of times the finger was tapped for this given touch. (read-only)

    Declaration

    Swift

    var tapCount: Int { get }

    Objective-C

    @property(nonatomic, readonly) NSUInteger tapCount

    Discussion

    The value of this property is an integer indicating the number of times the user tapped their fingers on a certain point within a predefined period. If you want to determine whether the user single-tapped, double-tapped, or even triple-tapped a particular view or window, you should evaluate the value returned by this method.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • timestamp timestamp Property

    The time when the touch occurred or when it was last mutated. (read-only)

    Declaration

    Swift

    var timestamp: NSTimeInterval { get }

    Objective-C

    @property(nonatomic, readonly) NSTimeInterval timestamp

    Discussion

    The value of this property is the time, in seconds, since system startup the touch either originated or was last changed. You can store and compare the initial value of this attribute to subsequent timestamp values of the UITouch instance to determine the duration of the touch and, if it is being swiped, the speed of movement. For a definition of the time-since-boot value, see the description of the systemUptime method of the NSProcessInfo class.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • phase phase Property

    The type of touch. (read-only)

    Declaration

    Swift

    var phase: UITouchPhase { get }

    Objective-C

    @property(nonatomic, readonly) UITouchPhase phase

    Discussion

    The property value is a constant that indicates whether the touch began, moved, ended, or was canceled. For descriptions of possible UITouchPhase values, see Touch Phase.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The gesture recognizers that are receiving the touch object. (read-only)

    Declaration

    Swift

    var gestureRecognizers: [AnyObject] { get }

    Objective-C

    @property(nonatomic, readonly, copy) NSArray *gestureRecognizers

    Discussion

    The objects in the array are instances of a subclass of the abstract base class UIGestureRecognizer. If there are no gesture recognizers currently receiving the touch objects, this property holds an empty array.

    Import Statement

    import UIKit

    Availability

    Available in iOS 3.2 and later.

  • Returns the current location of the receiver in the coordinate system of the given node.

    Declaration

    Swift

    func locationInNode(_ node: SKNode!) -> CGPoint

    Objective-C

    - (CGPoint)locationInNode:(SKNode *)node

    Parameters

    node

    A node that is a descendant of a scene presented in the window that received the touch event.

    Return Value

    The location of the touch in the node’s coordinate system.

    Import Statement

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • Returns the previous location of the receiver in the coordinate system of the given node.

    Declaration

    Swift

    func previousLocationInNode(_ node: SKNode!) -> CGPoint

    Objective-C

    - (CGPoint)previousLocationInNode:(SKNode *)node

    Parameters

    node

    A node that is a descendant of a scene presented in the window that received the touch event.

    Return Value

    The location of the touch in the node’s coordinate system.

    Import Statement

    import SpriteKit

    Availability

    Available in iOS 7.0 and later.

  • The phase of a finger touch.

    Declaration

    Swift

    enum UITouchPhase : Int { case Began case Moved case Stationary case Ended case Cancelled }

    Objective-C

    typedef enum { UITouchPhaseBegan, UITouchPhaseMoved, UITouchPhaseStationary, UITouchPhaseEnded, UITouchPhaseCancelled, } UITouchPhase;

    Constants

    • Began

      UITouchPhaseBegan

      A finger for a given event touched the screen.

      Available in iOS 2.0 and later.

    • Moved

      UITouchPhaseMoved

      A finger for a given event moved on the screen.

      Available in iOS 2.0 and later.

    • Stationary

      UITouchPhaseStationary

      A finger is touching the surface but hasn't moved since the previous event.

      Available in iOS 2.0 and later.

    • Ended

      UITouchPhaseEnded

      A finger for a given event was lifted from the screen.

      Available in iOS 2.0 and later.

    • Cancelled

      UITouchPhaseCancelled

      The system cancelled tracking for the touch, as when (for example) the user puts the device to his or her face.

      Available in iOS 2.0 and later.

    Discussion

    The phase of a UITouch instance changes in a certain order during the course of an event. You access this value through the phase property.

    Import Statement

    import UIKit

    Availability

    Available in iOS 2.0 and later.