gpt4 book ai didi

ios - UIPanGestureRecognizer-使用CATransform3D的translationInView

转载 作者:行者123 更新时间:2023-12-01 19:02:12 27 4
gpt4 key购买 nike

我正在尝试使用UIPanGestureRecognizer实现页面翻转动画。这是代码:

- (void)handlePan:(UIPanGestureRecognizer *)recognizer {

CGPoint location = [recognizer locationInView:self.view];
CGPoint translation = [recognizer translationInView:self.view];
CGPoint velocity = [recognizer velocityInView:self.view];

[recognizer setTranslation:CGPointZero inView:recognizer.view];

switch (recognizer.state) {
case UIGestureRecognizerStateChanged:
{

self.currentTranslation = self.currentTranslation + translation.x;

//only pan left
if (self.currentTranslation > 0.0) {
self.currentTranslation = 0.0;
}


CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
rotationAndPerspectiveTransform.m34 = 1.0 / -2000;

self.currentRotation = self.currentTranslation/2 * M_PI / 180.0f;
//dont rotate past -90 degrees
if (self.currentRotation <= -M_PI/2) {
self.currentRotation = -M_PI/2+0.0001;
}
rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, self.currentRotation, 0.0f, 1.0f, 0.0f);

float ypos = self.view.layer.position.y;

self.view.layer.anchorPoint = CGPointMake(0, 0.5);
self.view.layer.position = CGPointMake(0, ypos);
self.view.layer.transform = rotationAndPerspectiveTransform;


break;
}


default:
break;
}

}

动画有效,当我向左拖动时页面会旋转。但是,即使我以稳定,缓慢的速度移动手势,页面也会开始快速翻动。我希望页面随着触摸移动而“线性地”旋转,就像Flipboard应用一样。我该如何控制翻译速度呢?

最佳答案

翻译是累积的。在案例UIGestureRecognizerStateChanged之后将其添加到您的代码中。

    [recognizer setTranslation:CGPointZero inView:self.view];

关于ios - UIPanGestureRecognizer-使用CATransform3D的translationInView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22101476/

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