Mac Developer Library

Developer

AppKit Framework Reference NSTouch Class Reference

Options
Deployment Target:

On This Page
Language:

NSTouch

An instance of the NSTouch class is a snapshot of a particular touch at an instant in time.

A touch event is not persistent throughout the touch, new instances are created as the touch progresses. The identity property is used to follow a specific touch across its lifetime.

Touches do not have a corresponding screen location. The first touch of a touch collection is latched to the view underlying the cursor using the same hit detection as mouse events. Additional touches on the same device are also latched to the same view as any other touching touches. A touch remains latched to its view until the touch has either ended or is cancelled.

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.6 and later.
  • identity identity Property

    Use this property to track changes to a particular touch during the touch's life. (read-only)

    Declaration

    Swift

    var identity: protocol<NSCopying, NSObjectProtocol>? { get }

    Objective-C

    @property(readonly, strong) id<NSObject, NSCopying> identity

    Discussion

    While touch identities may be re-used, they are unique during the life of the touch, even when multiple devices are present.

    Identity objects implement the NSCopying protocol so that they may be used as keys in an NSDictionary. Use isEqual: to compare two touch identities.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • phase phase Property

    The current phase of the touch. (read-only)

    Declaration

    Swift

    var phase: NSTouchPhase { get }

    Objective-C

    @property(readonly) NSTouchPhase phase

    Discussion

    See NSTouchPhase for possible values.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • The normalized position of the touch. (read-only)

    Declaration

    Swift

    var normalizedPosition: NSPoint { get }

    Objective-C

    @property(readonly) NSPoint normalizedPosition

    Discussion

    The normalized position is a scaled value between (0.0) and (1.0,1.0), where (0.0,0.0) is the lower-left position on the touch device.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • isResting isResting Available in OS X v10.6 through OS X v10.9 Property

    Returns whether the touch is a resting touch. (read-only)

    Declaration

    Objective-C

    @property(readonly) BOOL isResting

    Discussion

    Resting touches occur when a user simply rests their thumb on the trackpad device.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.6 through OS X v10.9.

  • device device Property

    The digitizer that generated the touch. Useful to distinguish touches emanating from multiple-device scenario. (read-only)

    Declaration

    Swift

    var device: AnyObject? { get }

    Objective-C

    @property(readonly, strong) id device

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • The range of the touch device in points (72ppi). (read-only)

    Declaration

    Swift

    var deviceSize: NSSize { get }

    Objective-C

    @property(readonly) NSSize deviceSize

    Discussion

    The lower-left corner of the surface is considered (0,0).

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • The possible phases of a touch. These constants are used by phase.

    Declaration

    Swift

    struct NSTouchPhase : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var Began: NSTouchPhase { get } static var Moved: NSTouchPhase { get } static var Stationary: NSTouchPhase { get } static var Ended: NSTouchPhase { get } static var Cancelled: NSTouchPhase { get } static var Touching: NSTouchPhase { get } static var Any: NSTouchPhase { get } }

    Objective-C

    enum { NSTouchPhaseBegan = 1U << 0, NSTouchPhaseMoved = 1U << 1, NSTouchPhaseStationary = 1U << 2, NSTouchPhaseEnded = 1U << 3, NSTouchPhaseCancelled = 1U << 4, NSTouchPhaseTouching = NSTouchPhaseBegan | NSTouchPhaseMoved | NSTouchPhaseStationary, NSTouchPhaseAny = NSUIntegerMax }; typedef NSUInteger NSTouchPhase;

    Constants

    • Began

      NSTouchPhaseBegan

      A finger touched the device. Or, a resting touch transitioned to an active touch and resting touches are not wanted by the view hierarchy.

      Available in OS X v10.7 and later.

    • Moved

      NSTouchPhaseMoved

      A finger moved on the device.

      Available in OS X v10.7 and later.

    • Stationary

      NSTouchPhaseStationary

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

      Available in OS X v10.7 and later.

    • Ended

      NSTouchPhaseEnded

      A finger was lifted from the screen. Or, an active touch transitioned to a resting touch and resting touches are not wanted by the view hierarchy.

      Available in OS X v10.7 and later.

    • Cancelled

      NSTouchPhaseCancelled

      The system cancelled tracking for the touch, as when (for example) the window associated with the touch resigns key or is deactivated.

      Available in OS X v10.7 and later.

    • Touching

      NSTouchPhaseTouching

      Matches the NSTouchPhaseBegan, NSTouchPhaseMoved, or NSTouchPhaseStationary phases of a touch.

      Available in OS X v10.7 and later.

    • Any

      NSTouchPhaseAny

      Matches any phase of a touch.

      Available in OS X v10.7 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.