简体   繁体   中英

How to make UIGestureRecognizer in subview block UIGestureRecognizer in container superview

I have a container UIView that handles zoom and pan. Inside of this container view I have draggable views that manage their own UIPanGestureRecognizers. Currently, when I start panning a draggable item, the superview will also pan. In that situation Ijust want the draggable item to pan.

I tried various uses of UIPanGestureRecognizer delegate methods with no luck.

Looks like I missed trying one permutation of the recognizer delegates. This one did the job:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldBeRequiredToFailByGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    if(otherGestureRecognizer == myDraggableItemPanRecognizer) {
        return false
    } else {
        return true
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM