ios9 – ios 9 iphone 6S播放触觉反馈或振动

用户强力触摸后,我想像认行为一样振动手机.

是触觉吗如果是这样,我该怎么办?

解决方法

例如 swift(对于iPhone 6S)
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)

以防万一 – 这里是iPhone 7/7+的例子

对于强力触摸 – 您需要首先检测是否可用:

func is3dTouchAvailable(traitCollection: uitraitcollection) -> Bool {
    return traitCollection.forcetouchCapability == UIForcetouchCapability.available
}

然后在触摸事件中它将以touch.force的形式提供

func touchMoved(touch: UITouch,toPoint pos: CGPoint) {
    let location = touch.location(in: self)
    let node = self.atPoint(location)

    //...
    if is3dTouchEnabled {
        bubble.setPressure(pressurePercent: touch.force / touch.maximumPossibleForce)
    } else {
        // ...
    }
}

以下是代码示例的更详细示例:
http://www.mikitamanko.com/blog/2017/02/01/swift-how-to-use-3d-touch-introduction/

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...