如何使用UIGestureRecognizerDelegate?

Def*_*aur 6 uiscrollview uiview ios uipangesturerecognizer swift

我的设置

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

我有一个UIView(内部)a的子视图UIScrollView.两者都是相同的UIViewController.该UIView有一个UIPanGestureRecognizer被连接到它UIViewController.

UIScrollView用于向上和向下滚动.该UIPanGestureRecognizer用于滑开UIView.

问题

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

问题

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

我花了几个小时试图解决这个问题,我非常感谢你的帮助.

Def*_*aur 7

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

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

class CardViewController: UIViewController, UIGestureRecognizerDelegate

接下来,将此函数添加到以下主体UIViewController:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}
Run Code Online (Sandbox Code Playgroud)

最后,你这样做UIPanGestureRecognizer:

somePanGestureRecognizer.delegate = self