【问题标题】:How to use UIGestureRecognizerDelegate?如何使用 UIGestureRecognizerDelegate?
【发布时间】:2015-06-26 22:08:05
【问题描述】:

我的设置

我正在尝试复制 Google Now 的卡片界面。

我有一个UIView,它是(内部)UIScrollView 的子视图。两者都由同一个UIViewController 控制。 UIView 有一个由 UIViewController 附加的 UIPanGestureRecognizer

UIScrollView 用于上下滚动。 UIPanGestureRecognizer 用于扫掉UIView

问题

触摸UIView(卡片)时无法滚动

问题

如何实现UIGestureRecognizerDelegate 以在卡上启用gestureRecognizer(_:shouldRecognizeSimultaneouslyWithGestureRecognizer:) 以便让UIScrollView 滚动?

我已经花了几个小时试图解决这个问题,我将非常感谢您的帮助。

【问题讨论】:

    标签: ios swift uiview uiscrollview uipangesturerecognizer


    【解决方案1】:

    如果有人想知道如何做到这一点,答案如下:

    当你声明你的类时,在它的子类之后添加UIGestureRecognizerDelegate。这是我的情况:

    class CardViewController: UIViewController, UIGestureRecognizerDelegate

    接下来,将此函数添加到 UIViewController 的正文中:

    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return true
    }
    

    最后,你对UIPanGestureRecognizer

    somePanGestureRecognizer.delegate = self

    【讨论】:

      猜你喜欢
      • 2016-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多