【问题标题】:How to make device vibrate more intense?如何让设备振动更剧烈?
【发布时间】:2021-01-19 08:09:29
【问题描述】:

现在我有一个扩展程序可以让设备在应用程序的任何位置振动:

extension UIDevice {
    static func vibrate(style: UINotificationFeedbackGenerator.FeedbackType) {
        guard CHHapticEngine.capabilitiesForHardware().supportsHaptics else {
            AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
            return
        }
        let generator = UINotificationFeedbackGenerator()
        generator.notificationOccurred(style)
    }
}

问题出在使用触觉的设备上。现在我使用风格为warning 但设备振动非常微弱,甚至不明显。是否有其他方法可以使设备振动 2 次或更剧烈?

我在代码中尝试了不同的振动方式,但振动仍然很弱。

【问题讨论】:

  • 更多内脏?还是更激烈?
  • 对不起,更激烈
  • 您可以随时使用AudioServicesPlayAlertSound(kSystemSoundID_Vibrate),这是一个非常重的振动。

标签: ios swift iphone haptic-feedback


【解决方案1】:

CoreHaptic 中有这样的功能,这里是tutorial

// Create an intensity parameter:
let intensity = CHHapticEventParameter(parameterID: .hapticIntensity,
                                       value: initialIntensity)

// Create a sharpness parameter:
let sharpness = CHHapticEventParameter(parameterID: .hapticSharpness,
                                       value: initialSharpness)

// Create a continuous event with a long duration from the parameters.
let continuousEvent = CHHapticEvent(eventType: .hapticContinuous,
                                    parameters: [intensity, sharpness],
                                    relativeTime: 0,
                                    duration: 100)

do {
    // Create a pattern from the continuous haptic event.
    let pattern = try CHHapticPattern(events: [continuousEvent], parameters: [])
    
    // Create a player from the continuous haptic pattern.
    continuousPlayer = try engine.makeAdvancedPlayer(with: pattern)
    
} catch let error {
    print("Pattern Player Creation Error: \(error)")
}

continuousPlayer.completionHandler = { _ in
    DispatchQueue.main.async {
        // Restore original color.
        self.continuousPalette.backgroundColor = self.padColor
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-28
    • 2023-03-16
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    相关资源
    最近更新 更多