Closed cratter49 closed 6 years ago
It should, but there has been no discussion of this to date. If you or anyone wants to dive in and try to create a pull request I would be happy to take a look.
I don't currently have a solution but I've been inspecting iOS 9+ runtime headers and have discovered some properties in UITouch.h that may be useful to declare in a Category so we can use them at runtime. Such properties are _pressure
( setter: (void) _setPressure:(float)arg1 resetPrevious:(BOOL)arg2
) and _needsForceUpdate
( setter: (void)_setNeedsForceUpdate:(BOOL)arg1
).
I've also inspected the IOHIDEvent header in the IOKit and discovered pressure is used as well. So when setting the IOHID event of the UITouch and UIEvent there are tipPressure and barrelPressure parameters in IOHIDEventCreateDigitizerEvent which may need to be set for 3D touches.
Examples:
@interface UITouch ()
...
- (float) _pressure;
- (void) _setPressure:(float)arg1 resetPrevious:(BOOL)arg2;
- (void) _setNeedsForceUpdate:(BOOL)_needsForceUpdate;
...
@end
@implementation UITouch (KIFAdditions)
...
[self _setNeedsForceUpdate:YES];
[self _setPressure:pressureValue];
...
@end
IOHIDEventRef kif_IOHIDEventWithTouches(NSArray *touches) {
...
IOHIDEventCreateDigitizerFingerEventWithQuality(kCFAllocatorDefault, // allocator
timeStamp, // timestamp
(UInt32)[touches indexOfObject:touch] + 1, //index
2, // identity
eventMask, // eventMask
(IOHIDFloat)touchLocation.x, // x
(IOHIDFloat)touchLocation.y, // y
0.0, // z
touch._pressure, // tipPressure
0, // twist
5.0, // minor radius
5.0, // major radius
1.0, // quality
1.0, // density
1.0, // irregularity
(IOHIDFloat)isTouching, // range
(IOHIDFloat)isTouching, // touch
0); // options
...
}
Additionally, in order to simulate duration in a UIEvent which may be necessary to send a 3D touch I first set the timestamp of its UITouch with UITouchPhase = UITouchPhaseBegan to the current time. Then I set the timestamp of its final UITouch with UITouchPhase = UITouchPhaseEnded to the initial timestamp plus the specified duration.
The issue is that after adding all of this new information to UITouch and attempting to create an IOHIDEvent based off of this information I've had no success in being able to synthesize a 3D touch on an iOS application that utilizes 3D touch on my iPhone 6S. The end result of my efforts is that a normal touch is synthesized but without force. If you could let me know if I've made any mistakes or have any advice on what I should attempt next and/or where I should research more information on this subject I would greatly appreciate it.
@cratter49 Thank you for that write up. It seems you're getting closer to understanding the mechanics involved. Seems that a logical next-step could be to put together a small proof of concept. We look forward to, and greatly appreciate any PR you submit that could make 3D touch work with KIF.
Is the KIF framework going to support 3D touch in the near future?