我遇到了同样的问题,并找到了两种解决方法。
1.这种方式可以同时识别平移和滑动,这可能是您想要的。这不是我想要的,因为我不希望页面在我向上/向下滑动时改变。对于此方法,您必须使您的类成为滑动手势识别器的代表。
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
2.这种方式可以防止平移直到它知道滑动失败,这意味着滑动永远不会与平移同时发生。我相信,如果您的滑动是垂直的,这只会对您有用,因为水平的滑动总是会阻止平移。
//Cheat to get the pan gesture from the pageviewcontroller. You should iterate and make sure you get the right one.
UIPanGestureRecognizer * panGR = self.pageViewController.gestureRecognizers[0];
// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
UISwipeGestureRecognizer * swipeGestureRec = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(openArchive:)];
swipeGestureRec.direction = UISwipeGestureRecognizerDirectionDown;
[panGR requireGestureRecognizerToFail:swipeGestureRec];
[self.view addGestureRecognizer:swipeGestureRec];
swipeGestureRec = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(closeArchive:)];
swipeGestureRec.direction = UISwipeGestureRecognizerDirectionUp;
[panGR requireGestureRecognizerToFail:swipeGestureRec];
[self.view addGestureRecognizer:swipeGestureRec];