最近在项目中使用了UIPageViewController来翻页,在VIEW上又使用了UITableView,两者都有一个UIPanGestureRecognizer手势,在UITableView上托动的时候两者都接收到了这个UIPanGestureRecognizer手势,
这样的话,会导致手势混乱。解决思路:当触发一个UIPanGestureRecognizer手势的时候,另外一个不响应。这样就不冲突了。
直接上代码解决代码啦,记录一下UIPageViewController的旅程。
第一步:设置UIPageViewController的手势委托
self.view.gestureRecognizers = self.pageViewCtrl.gestureRecognizers;
for (UIGestureRecognizer* recognizer in self.pageViewCtrl.gestureRecognizers) {
recognizer.delegate=self;
}
第二步:利用-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
来解决冲突。
#pragma mark resolve UITableView and UIPageViewController panGesture Conflict
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] &&
[otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
return NO;
}
return NO;
}