gpt4 book ai didi

ios - 适用于 iPad 的 3D touch 对应

转载 作者:行者123 更新时间:2023-11-28 11:47:09 29 4
gpt4 key购买 nike

我曾尝试使用 swift 开发一款利用 iPhone 的 3D 触摸硬件的游戏。然而,当我将我的应用程序提交到 App Store 时,它​​被拒绝了,因为该游戏无法在 iPad 上玩

我的问题是,为非 3D 触摸设备实现类似功能的最佳方式是什么?我现在的做法是实现以下方法

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

}

}

在非 3D 触摸设备上运行后者时,调试 touch.maximumPossibleForce 的值返回 0

最佳答案

您无法在不支持强制触摸的设备上检测到它。

但也许您可以在 UITouch 上使用 majorRadius 属性。它为您提供触摸半径。

借助半径,您可以让没有 3d 触控设备的用户通过手指的角度来控制您的游戏:

enter image description here

这是上面例子的代码:

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 = "-"
}

关于ios - 适用于 iPad 的 3D touch 对应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52432884/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com