UISelectionFeedbackGenerator() 不适用于 iPhone 7

Kev*_*ser 7 iphone ios swift haptic-feedback ios10

我想在我的应用程序中使用一些触觉。我正在使用,UISelectionFeedbackGenerator但它不起作用。我正在使用 iOS 10 在真正的 iPhone 7 上进行测试。这两行应该可以发挥作用 - 但没有任何反应:

let generator = UISelectionFeedbackGenerator()
generator.selectionChanged()
Run Code Online (Sandbox Code Playgroud)

ull*_*trm 8

似乎AVFoundation(或者可能只是AVCaptureSession)在某种程度上弄乱了触觉反馈!没有AVFoundation,我的触觉反馈有效。一旦我把它放在那里,它就停止工作。


Mic*_*ael 5

以下是一些适用于旧设备的替代方案:

import AudioToolbox

AudioServicesPlaySystemSound(1519) // Actuate `Peek` feedback (weak boom)
AudioServicesPlaySystemSound(1520) // Actuate `Pop` feedback (strong boom)
AudioServicesPlaySystemSound(1521) // Actuate `Nope` feedback (series of three weak booms)
Run Code Online (Sandbox Code Playgroud)


Can*_*ich 1

在你打电话之前selectionChanged(),你需要先打电话generator.prepare()。这会唤醒 Taptic 引擎。不过,它会保持活动状态几秒钟,因此,prepare()如果您要selectionChanged()在路上打电话,请确保再次拨打。

let generator = UISelectionFeedbackGenerator()
generator.prepare()
generator.selectionChanged()
Run Code Online (Sandbox Code Playgroud)

  • @KevinLieser 我对触觉反馈和 AVFoundation 也有问题! (2认同)