gpt4 book ai didi

ios - 快速改变手势速度

转载 作者:行者123 更新时间:2023-11-29 05:16:10 25 4
gpt4 key购买 nike

是否可以减慢平移手势,使其以较低的速度移动。

这是我用来移动 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
}
}

最佳答案

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 初始位置:CGPoint? -> 全局

初始位置.x = (初始位置??0)

(初始位置.x)! = (初始位置.x)! + (sender.velocity(in: colorSlider!).x/60) - 对于水平

(初始位置.y)! = (初始位置.y)! + (sender.velocity(in: colorSlider!).y/60) - 对于垂直

谢谢。”

关于ios - 快速改变手势速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59164286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com