ios - Apple 是否在 Swift 中弃用了 iPhone 3D touch?

标签 ios iphone 3dtouch force-touch

我在 2 年前使用 Swift 中的 3D 触摸功能制作了一款游戏,因为它很新,但我从未发布过这款游戏,因为我获得了一份新契约(Contract)。现在我有时间想发布它,但代码不再有效。 (3D 触摸自定义操作,而不是 peek & pop 操作)

当我打印触摸结果时,力值将始终返回 0.0,如下所示:

[<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}]

我知道 Apple 出于成本原因正在从设备中删除此功能,但我记得,iPhone 11 pro 仍然具有此功能。有谁知道这个值是否被弃用?

最佳答案

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

这些设备支持触觉触控:

  • iPhone 11
  • iPhone 11 专业版
  • iPhone 11 专业版
  • iPhone XR

这些设备支持 3D Touch:

  • iPhone 6s
  • iPhone 6s Plus
  • iPhone 7
  • iPhone 7 Plus
  • iPhone 8
  • 苹果手机 8 加
  • iPhone X
  • iPhone XS
  • iPhone XS Max

数据源(2020 年 1 月)Change 3D or Haptic Touch sensitivity on your iPhone

解决方案

检查设备上是否存在 3D Touch

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

关于ios - Apple 是否在 Swift 中弃用了 iPhone 3D touch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59821388/

相关文章:

ios - 在 swift 中使用带有参数的预定义函数作为完成 block

iphone - 用于在 iPhone 上读取音符的 API

ios - iOS 键盘的最大高度是多少?

iphone - Objective-C 中的文本长度

cordova - 类似 Instagram 的强制触摸弹出模式

ios - 2 GestureRecognizer 之间的区别

ios - UILabel 初始化时调用的函数

android - flutter 中的自定义时间轴 View

iphone - CGBitmapContextCreate 的内存使用率非常高

ios - 应用程序关闭时 3D Touch UIapplicationShortcut 不起作用