Reputation: 159
I made a game 2 years ago using the 3D touch feature in Swift because it was pretty new but I've never released the game because I got a new contract. Now I have time I want to release it but the code doesn't work any more. (3D touch custom actions, not the peek & pop action)
When I print the touch result, the force value will always return 0.0 like this:
[<UITouch: 0x102613850> phase: Began tap count: 2 force: 0.000 window: <UIWindow: 0x10222bf70; frame = (0 0; 414 896); gestureRecognizers = <NSArray: 0x28011cde0>; layer = <UIWindowLayer: 0x280f41840>> view: <UIView: 0x102083080; frame = (0 82; 414 780); autoresize = RM+BM; gestureRecognizers = <NSArray: 0x2801a0c30>; layer = <CALayer: 0x280f2a540>> location in window: {299.33332824707031, 661.66665649414062} previous location in window: {299.33332824707031, 661.66665649414062} location in view: {299.33332824707031, 579.66665649414062} previous location in view: {299.33332824707031, 579.66665649414062}]
I know Apple is removing this feature from devices cause of the cost but as I remember, the iPhone 11 pro still has it. Does anyone know if this value is deprecated?
Upvotes: 0
Views: 810
Reputation: 9915
Every touch starts as a contact with no force at all, as soon as the user's finger makes contact (or even near-contact) with the screen. The force only starts to build as the user's finger is compressed against the screen. UITouch force on touchesBegan is zero
Force Touch
The technology was first unveiled on September 9, 2014, during the introduction of Apple Watch. Starting with the Apple Watch, Force Touch has been incorporated into many products within Apple’s lineup. This notably includes MacBooks and the Magic Trackpad 2. The technology is known as 3D Touch on the iPhone models. source
These devices support Haptic Touch:
These devices support 3D Touch:
Datasource (2020 January) Change 3D or Haptic Touch sensitivity on your iPhone
Solution
Check a presence of 3D Touch on a device
if traitCollection.forceTouchCapability == .available {
}
The iOS trait environment is exposed though the traitCollection property of the UITraitEnvironment protocol. This protocol is adopted by the following classes: UIScreen, UIWindow, UIViewController, UIPresentationController, and UIView. source
Upvotes: 5