在处理longPressed手势时禁用UIPageViewController手势识别器

时间:2012-05-21 17:55:29

标签: iphone cocoa-touch uigesturerecognizer

我有一个UIPageViewController并且每个页面在页面上包含多个UIViews,每个UIView在longPress手势之后允许Pan手势,我在contentVC中使用以下委托,但是看起来pageVC不关心我在下面的限制并且它继续翻页!我在平移时是否必须执行任何操作才能禁用翻页? (最后的手段是在PageVC中设置变量,如canTurn,并在平移运行时将其设置为NO。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

    if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] &&
        [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        return YES;
    }
    return NO;
}

1 个答案:

答案 0 :(得分:1)

你应该在PageVC本身中添加-gestureRecognizer:shouldReceiveTouch:方法,或者如果你不想在PageVC本身中添加它,你可以让代表处理它

像:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
   if(someCase)
   {
      return yes;
   }

   return no;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
   return [delegate shouldHandle:.....];
}