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

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

概述用户强力触摸后,我想像默认行为一样振动手机. 是触觉吗如果是这样,我该怎么办? 例如 swift(对于iPhone 6S) import AudioToolboxAudioServicesPlaySystemSound(1519) // Actuate `Peek` feedback (weak boom)AudioServicesPlaySystemSound(1520) // Actua 用户强力触摸后,我想像默认行为一样振动手机.

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

解决方法 例如 swift(对于iPhone 6S)
import AudioToolBoxAudioServicesPlaySystemSound(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/

总结

以上是内存溢出为你收集整理的ios9 – ios 9 iphone 6S播放触觉反馈或振动全部内容,希望文章能够帮你解决ios9 – ios 9 iphone 6S播放触觉反馈或振动所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1110496.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存