我已经为此奋斗了大约一个小时。我试图让我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,因此它的一部分显示在屏幕上,因此它不会消失。但是,当它在该位置时,当我将它滑回左侧时,它会一直跳到原点,而不是跟随平移手势。
这是为什么?我该如何解决?
谢谢