gpt4 book ai didi

ios - 捏合(缩放)手势无法正确缩放

转载 作者:行者123 更新时间:2023-11-29 04:45:36 29 4
gpt4 key购买 nike

我试图弄清楚为什么我的缩放在我的 OpenGL 相机上表现得很奇怪。它的目的是放大和缩小,但它的缩放非常随机。

这是我的代码:

- (void)pinchDetected:(UIPinchGestureRecognizer *)pinchRecognizer
{
NSLog (@"%@", @"Pinching");

if (pinchRecognizer.state == UIGestureRecognizerStateBegan ||
pinchRecognizer.state == UIGestureRecognizerStateChanged ||
pinchRecognizer.state == UIGestureRecognizerStateEnded) {
currentScale = pinchRecognizer.scale;
}

if(lastScale < currentScale) {
_camera.z += currentScale * 0.01f;
lastScale = currentScale;
}

if (lastScale > currentScale)
{
_camera.z -= currentScale * 0.01f;
lastScale = currentScale;
}

}

最佳答案

如果你有一些乘法的东西并且你想把它变成加法,你需要取一个对数:

- (void)pinchDetected:(UIPinchGestureRecognizer *)pinchRecognizer
{
if ((gesture.state == UIGestureRecognizerStateBegan) ||
(gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
_camera.z += log(gesture.scale); // you'll probably want to multiply this by some constant
gesture.scale = 1.0;
}
}

关于ios - 捏合(缩放)手势无法正确缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9692074/

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