是否可以减慢平移手势,使其以较低的速度移动。
这是我用来移动3d对象的代码
@objc func handlePan(gestureRecognize: UIPanGestureRecognizer) {
let numberOfTouches = gestureRecognize.numberOfTouches
let translation = gestureRecognize.translation(in: gestureRecognize.view!)
var widthRatio = Float(translation.x) / Float(gestureRecognize.view!.frame.size.width) - lastWidthRatio
if (numberOfTouches == fingersNeededToPan) {
// WIDTH constraints
if(widthRatio >= maxWidthRatioRight) {
widthRatio = maxWidthRatioRight
}
if(widthRatio <= maxWidthRatioLeft) {
widthRatio = maxWidthRatioLeft
}
self.artRoomScene.boxnode.eulerAngles.y = Float(2 * Double.pi) * widthRatio
//for final check on fingers number
lastFingersNumber = fingersNeededToPan
}
lastFingersNumber = (numberOfTouches>0 ? numberOfTouches : lastFingersNumber)
if (gestureRecognize.state == .ended && lastFingersNumber==fingersNeededToPan) {
lastWidthRatio = widthRatio
}
}
答案 0 :(得分:0)
Access the velocity of a pan gesture
“ sender.velocityInView(self.view)为您提供每秒的像素速度。为了获得准确的速度,您需要通过将其除以60来将速度更改为每分钟像素数,如下所示:
sender.velocityInView(self.view).x / 60-对于水平
sender.velocityInView(self.view).y / 60-对于垂直
因此,您只需将其添加初始值即可更新位置,如下所示:
var initialLocation:CGPoint? ->全球
initialLocation.x =(initialLocation ?? 0)
(initialLocation.x)! =(initialLocation.x)! +(sender.velocity(in:colorSlider!)。x / 60)-对于水平
(initialLocation.y)! =(initialLocation.y)! +(sender.velocity(in:colorSlider!)。y / 60)-对于垂直
谢谢。”