OGeek|极客世界-中国程序员成长平台

标题: ios - 我可以在 iOS 上使用 3D Touch 为手势添加反馈(缺口)吗? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:37
标题: ios - 我可以在 iOS 上使用 3D 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 是否可以实现相同的功能?



Best Answer-推荐答案


是的,使用 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 - 我可以在 iOS 上使用 3D Touch 为手势添加反馈(缺口)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33395171/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4