解决方法
例如
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/