ios9 – ios 9 iphone 6S播放触觉反馈或振动
2019年11月21日
作者:佚名
用户强力触摸后,我想像默认行为一样振动手机.
是触觉吗如果是这样,我该怎么办?
解决方法
例如
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/
以上是来客网为你收集整理的ios9 – ios 9 iphone 6S播放触觉反馈或振动全部内容,希望文章能够帮你解决ios9 – ios 9 iphone 6S播放触觉反馈或振动所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。