Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for force touch in SPTouch #51

merged 2 commits into from Jan 28, 2016
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

@@ -117,6 +117,9 @@ typedef NS_ENUM(NSInteger, SPTouchPhase)
/// The display object at which the touch occurred.
@property (nonatomic, readonly) SPDisplayObject *target;

/// The amount of force that was applied to the touch, as a factor from 0 to 1.
@property (nonatomic, readonly) float forceFactor;


@@ -27,6 +27,7 @@ @interface SPTouch ()
@property (nonatomic, assign) SPTouchPhase phase;
@property (nonatomic, strong) SPDisplayObject *target;
@property (nonatomic, assign) size_t touchID;
@property (nonatomic, assign) float forceFactor;


@@ -41,6 +42,7 @@ @implementation SPTouch
SPTouchPhase _phase;
SPDisplayObject *_target;
size_t _touchID;
float _forceFactor;

#pragma mark Initialization
@@ -140,6 +142,7 @@ - (instancetype)copyWithZone:(NSZone *)zone
clone->_tapCount = _tapCount;
clone->_timestamp = _timestamp;
clone->_target = [_target retain];
clone->_forceFactor = _forceFactor;
return clone;

@@ -197,6 +197,7 @@ - (SPTouch *)createOrUpdateTouch:(SPTouch *)touch
currentTouch.previousGlobalX = touch.previousGlobalX;
currentTouch.previousGlobalY = touch.previousGlobalY;
currentTouch.phase = touch.phase;
currentTouch.forceFactor = touch.forceFactor;
currentTouch.timestamp = _elapsedTime;

if (currentTouch.phase == SPTouchPhaseBegan)
@@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) NSInteger tapCount;
@property (nonatomic, assign) SPTouchPhase phase;
@property (nonatomic, strong, nullable) SPDisplayObject *target;
@property (nonatomic, assign) float forceFactor;


@@ -627,7 +627,16 @@ - (void)processTouchEvent:(UIEvent *)event
touch.previousGlobalY = previousLocation.y * yConversion;
touch.tapCount = (int)uiTouch.tapCount;
touch.phase = (SPTouchPhase)uiTouch.phase;
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnavailableInDeploymentTarget"
if ([uiTouch respondsToSelector:@selector(force)] && uiTouch.maximumPossibleForce > 0) {
touch.forceFactor = uiTouch.force / uiTouch.maximumPossibleForce;
} else {
touch.forceFactor = 0;
#pragma clang diagnostic pop
touch.touchID = (size_t)uiTouch;

[_touchProcessor enqueueTouch:touch];

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.