Reputation: 265
I have attempted to develop a game using swift that leverages the 3D touch hardware of iPhones. However, as I was submitting my app to the App Store, it got rejected because the game wasn't playable on iPads.
My question is, what is the best way of implementing a similar functionality for non 3D touch devices? The way I am doing right now is by implementing the following method
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
if self.didStartGame, let touch = touches.first {
let maximumPossibleForce = touch.maximumPossibleForce
let force = touch.force
let normalizedForce = min(force/maximumPossibleForce * 2.5, 1)
// Added game-related code here to modify scene accordingly
}
}
When running the latter on non 3D touch devices, debugging the value of touch.maximumPossibleForce
returns 0
.
Upvotes: 0
Views: 147
Reputation: 27620
You cannot detect force touch on devices that that don't support it.
But maybe you could use the majorRadius
property on UITouch
. It gives you the radius of the touch.
With the radius you can allow users that don't have a 3d touch device to control your game with the angle of their finger:
This is the code for the above example:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let pseudoForce = touches.first?.majorRadius else { return }
label.text = "\(pseudoForce)"
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let pseudoForce = touches.first?.majorRadius else { return }
label.text = "\(pseudoForce)"
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
label.text = "-"
}
Upvotes: 2