仅当滚动内容到达边缘时才识别 UIScrollView 中的滑动手势

Recognize swipe gesture in UIScrollView only when scrolling content reach the edge

UIScrollView 启用了垂直滚动。我想要做的是添加一个方向为 .down 的滑动手势,当用户因为内容到达边缘而无法再滚动内容时,该手势将被识别。

我正在尝试使用 require(toFail:) 但它无法正常工作。

let swipeDown = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeDown.direction = UISwipeGestureRecognizerDirection.down
swipeDown.require(toFail: self.scrollView.panGestureRecognizer)
self.scrollView.addGestureRecognizer(swipeDown)

我还添加了UIGestureRecognizerDelegate方法来同时识别:

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

如何始终优先考虑 scrollView 中的滚动内容以及何时无法再检测到滑动?

好的,我解决这个问题的方法只是检查 contentOffset 是否达到点 0.0,如果是,则禁用滚动并激活其他手势。对于我来说这就足够了。

if scrollView.contentOffset.y == 0.0 {
    print("content on top")

    // use delegate method here to manage the gestures

}