UIPanGestureRecognizer不在一个方向上平移

时间:2012-05-16 19:57:42

标签: iphone objective-c uiview uigesturerecognizer uipangesturerecognizer

我一直在争夺这个约一个小时。我试图让我的UIView平移与iOS Facebook应用程序平移主UIView相同,并在左侧显示导航表。因此,当您向右滑动时,它将一直向右平移并显示导航表。您可以将其滑回左侧。所以它基本上就像一个滑块。

我已将UIPanGestureRecognizer分配给UIView。这是我的selector手势:

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

    CGPoint newTranslation = [recognizer translationInView:self.view];

    NSLog(@"%f", newTranslation.x + lastTranslation.x);

    // only pan appropriately when view is within correct bounds
    if (lastTranslation.x + newTranslation.x >= 0 && lastTranslation.x + newTranslation.x <= 255)
    {

        self.navController.view.transform = CGAffineTransformMakeTranslation(newTranslation.x, 0);

        if (recognizer.state == UIGestureRecognizerStateEnded) {

            // if navcontroller is at less than 145px, snap back to 0
            if (newTranslation.x + lastTranslation.x <= 145)
                self.navController.view.transform = CGAffineTransformMakeTranslation(0, 0);

            // else if its at more than 145px, snap to 255
            else if (newTranslation.x + lastTranslation.x >= 145)
                self.navController.view.transform = CGAffineTransformMakeTranslation(255, 0);

            lastTranslation.x += newTranslation.x;
        }
    }
}

当向右滑动UIView时,这非常有效。然后它会粘在255px上,因此它的一部分显示在屏幕上,所以它不会消​​失。但是,当它位于该位置时,当我将其向左滑动时,它会一直跳到原点,而不是跟随平移手势。

为什么?我该如何解决?

由于

0 个答案:

没有答案