ios - 我可以使用 3D Touch 在 iOS 上为手势添加反馈(凹口)吗?

标签 ios macos 3dtouch force-touch

在 OS X 上使用 Force Touch 应用程序可以提供反馈或缺口(触觉/触觉?),如 Apple 的示例所述:

Map rotation: You'll feel a notch when you rotate the compass to north in Maps.

除了旧的音频 API 使设备振动 (AudioServicesPlayAlertSound) 之外,3D Touch 是否可以做同样的事情?

最佳答案

是的,使用 UIFeedbackGenerator在 iOS 10+ 支持的设备上你可以这样做:

var feedbackGenerator: UISelectionFeedbackGenerator

func prepare() {
    // Instantiate a new generator.
    feedbackGenerator = UISelectionFeedbackGenerator()

    // Prepare the generator when the gesture begins.
    feedbackGenerator?.prepare()
}

func notch() {
    // Trigger selection feedback.
    feedbackGenerator?.selectionChanged()

    // Release the current generator.
    feedbackGenerator = nil
}

关于ios - 我可以使用 3D Touch 在 iOS 上为手势添加反馈(凹口)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33395171/

相关文章:

ios - 不同的 UIButton accessibilityLabel 取决于按钮是否被选中

macos - 用于创建以当前日期命名的文件的 OS X 终端命令

mysql - Applescriptable mySQL 客户端 - 低成本还是免费?

ios - 如何以编程方式检查 iPhone 中可用的 3D Touch?

ios - 根据预览 View Controller 的 PHAsset 大小计算 preferredContentSize

ios - [UIScreen screens] 什么时候返回一个空数组

ios - 何时调用 addChildViewController

xcode - 在 Mac OS X Cocoa 应用程序中添加 ViewController 的标准方法是什么? (或者是必需的?)

ios - 禁用 UITableViewCell 中 UIButton 的 3D 触摸

ios - 另一个 UIView 的 UIView subview 是 UIViewController 的 subview ,在 iOS 中没有以 UIViewController 为中心