【问题标题】:SWRevealViewController pan gesture recogniser issueSWRevealViewController 平移手势识别器问题
【发布时间】:2014-07-23 09:07:48
【问题描述】:

我正在使用来自 John-Lluch 的 SWRevealViewController。我需要使用平移手势来查看侧边栏,并且我正在使用滑动来查看我的上一篇和下一篇文章。但是,只能检测到平移手势。

更新:如果我禁用平移手势,我的滑动手势会起作用。

平移手势

 [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

滑动手势

UISwipeGestureRecognizer *left = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)] autorelease];
left.direction = UISwipeGestureRecognizerDirectionLeft;

UISwipeGestureRecognizer *right = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)] autorelease];
right.direction = UISwipeGestureRecognizerDirectionRight;

[self.view addGestureRecognizer:left];
[self.view addGestureRecognizer:right];

【问题讨论】:

  • 添加更多代码或细节以帮助解释您使用滑动手势识别器的原因...
  • 我在 SWRevealViewController 中没有问题,请检查您的滑动手势
  • 为什么不使用它:-(IBAction) SwipeMe : (UISwipeGestureRecognizer *) recognizer{ NSLog(@"swiped"); } 只需将其链接到您的视图即可。
  • @Watsche 如果我禁用平移手势,我的滑动手势会起作用。
  • @NKB 我已经在我的内容中解释过了。 pan是打开侧边栏,滑动阅读文章。

标签: ios iphone uipangesturerecognizer uiswipegesturerecognizer


【解决方案1】:
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

[self.view addGestureRecognizer:left];

注意到区别了吗?将 SwipeGesture 实现为您的 .h 中的属性,或将其放入您的 .xib 并将其链接到您的 .h

【讨论】:

    【解决方案2】:

    很难同时处理平移和滑动手势识别器。您将处理用于平移手势的 SWRevealViewController 委托以及用于当前视图控制器的滑动手势。

    苹果建议区分手势,您可以使用以下方法

    - (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
        return YES;
    }
    

    摘自Apple Documentation:

    当通过以下任一方式识别手势时调用此方法 手势识别器或其他手势识别器会阻止另一个 手势识别器从识别其手势。请注意,返回 YES保证允许同时识别;返回 NO, on 另一方面,不能保证防止同时识别 因为其他手势识别器的委托可能会返回 YES。

    【讨论】:

    • 嗨,我已经为该方法启用了“是”,但平移识别器仍然超过了滑动移动
    • 它会超车,但它应该检测到两个识别器...您无法优先处理手势...
    猜你喜欢
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多