1

我正在尝试用来UIPanGestureRecognizer翻转 UIView。我正在使用下面的代码来处理翻转视图,

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

    CGPoint translation = [gesture translationInView:self.view];

    NSLog(@"PAN X VALUE %f", translation.x );

    double percentageOfWidth = translation.x / (gesture.view.frame.size.width / 2);

    float angle = (percentageOfWidth * 100) * M_PI_2 / 180.0f;

    CALayer *layer = testView.layer;
    CATransform3D flipTransform = CATransform3DIdentity;
    flipTransform.m34 = -0.002f;

    flipTransform = CATransform3DRotate(flipTransform, angle, 0.0f, 1.0f, 0.0f);
    layer.transform = flipTransform;

}

我的问题是当我平移时,有时会发生一些快速跳跃,我相信那是因为translation.x(PAN X VALUE)值从前面的几个点跳跃,就我而言,我需要它非常平滑。

非常感谢任何帮助。

提前致谢。

4

2 回答 2

0

您可以使用gestureRecognizerShouldBegin可以限制UIPanGestureRecognizer灵敏度的方法。

例子:

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)panGestureRecognizer {
    CGPoint translation = [panGestureRecognizer translationInView:self.view];
    return fabs(translation.y) < fabs(translation.x);
}
于 2013-11-14T08:23:22.777 回答
0

这是我为立方体旋转解决这个问题的方法 - 只需将拖动的数量除以:

- (void)panHandle:(UIPanGestureRecognizer*)recognizer;
{
    if ([recognizer state] == UIGestureRecognizerStateBegan)
    {
        CGPoint translation = [recognizer translationInView:[self superview]];
        _startingX = translation.x;
    }
    else if ([recognizer state] == UIGestureRecognizerStateChanged)
    {
        CGPoint translation = [recognizer translationInView:[self superview]];
        CGFloat angle = -(_startingX - translation.x) / 4;
        //Now do translation with angle
        _transitionContainer.layer.sublayerTransform = [self->_currentMetrics asTransformWithAngle:angle];
    }
    else if ([recognizer state] == UIGestureRecognizerStateEnded)
    {
        [self transitionOrReturnToOrigin];
    }
}
于 2013-11-14T22:12:49.620 回答