Working with the new Force property, how to detect changes in pressure?

Hi, I was looking into 3D touch and what I want to do is to is to respond to the user when he/she presses harder or softer however I'm not sure how to detect it.


According to the documentation, force is a property of a touch event but events are triggered when the user begins touching or moves the finger.


Basically, I have 2 questions


1) What the value of force means in the touchesBegin event? Wouldn't be always some very low number because the events is fired when the user begins the touch event?


2) Does pressing harder or lighter constitutes to a movement? Maybe I can get updated value in the touchesMoved when the user changes the pressure? If not, how to continuously get the current force?


Thanks!

Accepted Reply

1) The value in touchesBegin will be the initial force being applied when the touch event begins. The value will be in the range of 0 to maximumPossibleForce. In general it will indeed likely be a low number, but you should not build any assumptions based on what it will be. It'll be important for you to get a device that supports 3D Touch and see what works well for your application.


2) Yes, it's possible that simply pressing harder or software without actually moving will generate "move" events. This is one thing to watch out for. Making an assumption that a move event actually changes the x or y position of the touch can potentially confuse your app. You need to be prepared to handle move events that only change the force value.


Out of curiousity, can you give some more details as to what you're trying to do? I just want to make sure that the higher level view controller APIs wouldn't satisfy your needs and that you would actually need to use the force property. What type of app are you working on?

Replies

1) The value in touchesBegin will be the initial force being applied when the touch event begins. The value will be in the range of 0 to maximumPossibleForce. In general it will indeed likely be a low number, but you should not build any assumptions based on what it will be. It'll be important for you to get a device that supports 3D Touch and see what works well for your application.


2) Yes, it's possible that simply pressing harder or software without actually moving will generate "move" events. This is one thing to watch out for. Making an assumption that a move event actually changes the x or y position of the touch can potentially confuse your app. You need to be prepared to handle move events that only change the force value.


Out of curiousity, can you give some more details as to what you're trying to do? I just want to make sure that the higher level view controller APIs wouldn't satisfy your needs and that you would actually need to use the force property. What type of app are you working on?

Thank for the excelent answer!


I'm thinkering in SpriteKit to use force as part of the gameplay. Unfortunately, probably it would take some time to get my hands on an actual 3D Touch enabled device.


There're few things more that I'm curious about. I would be happy if I can get an answer.


1) What is the meaning of standard touch that will have 1.0 value? I mean the physical meaning, like is it basically the normal touch of average person without intention of pressing?


2) How much force is the maximu force? Again, I'm interested about the feeling in the physical world. Let's say, will the maximum measurable force be able to break an average chocolate bar or does it max out on some lighter force? Is the force reported linearly? Can I assume that 0.4 is twice the force of 0.2?


3) Is 3D touch multitouch? Can I have readings from two touches simultaneously?

Sure thing, happy to help. In the context of a game it makes perfect sense to operate on the force values directly. Unfortunately you really cannot develop something like that without trying it on actual hardware.


1) What is the meaning of standard touch that will have 1.0 value? I mean the physical meaning, like is it basically the normal touch of average person without intention of pressing?


Yes, that's right.


2) How much force is the maximu force? Again, I'm interested about the feeling in the physical world. Let's say, will the maximum measurable force be able to break an average chocolate bar or does it max out on some lighter force? Is the force reported linearly? Can I assume that 0.4 is twice the force of 0.2?


That's a little bit like asking "how blue is the blue sky?" 🙂 From my completely subjective experience, it is a decent amount of force, one that I would characterize as intentionally pressing harder than a normal tap. These are exactly the types of questions that you need to have a device to experience it with. The details of the progression for the force are an implementation detail so you cannot make any assumptions about whether it's linear or not.


Depending on what you're trying to do specifically, you might want to come up with some kind of quantization of force similar to how peek and pop works. From my experience, this takes some trial and error to get right based on an app's interaction. Alternatively if you were trying to develop something that, for example, changed the radius of a pen based on the pressure then you wouldn't necessarily care about the actual values and rather focused on the percent of the max force. So it really depends what you're trying to accomplish.


3) Is 3D touch multitouch? Can I have readings from two touches simultaneously?


Yes, each UITouch has an independent force value.

Thanks again, now it's crystal clear 🙂


Oh, one more thing: Is there any way to trigger haptic feedback in the app? I guess sound and visual feedback is going to do good enough job but haptic feed back could make it even better I believe. It could be really nice when used with quantization.

No, there is no API to directly trigger the haptic feedback. That's a great bug report to file if it's important to you (yes, it will be marked as a duplicate but it's helpful for us to have dupes to understand the breadth of developers that are interested so please do file a bug report).

Is this still the case? I'd really like an API like OS X's:


NSHapticFeedbackManager.defaultPerformer().performFeedbackPattern(.Alignment, performanceTime: .Now)


So that I can tell the user when she is rotating an object that it is axially-aligned (as I do on OS X).