Can I add feedback (notch) to a gesture on iOS using 3D Touch?

226 Views Asked by At

With Force Touch on OS X applications can provide a feedback or a notch (haptics/taptics?) like Apple's example describes:

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

Is the the same thing possible with 3D Touch beyond just the old audio API to vibrate the device (AudioServicesPlayAlertSound)?

1

There are 1 best solutions below

0
On BEST ANSWER

Yes, using UIFeedbackGenerator in iOS 10+ on supported devices you could do something like this:

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
}