简体   繁体   中英

Preferring UITableView's reorder control gesture over custom pan gesture

I have a UITableView with a custom UIPanGestureRecognizer attached, and by using shouldRecognizeSimultaneouslyWith I'm getting the expected behaviour between my custom gesture and the normal scroll gesture on the table view:

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        return otherGestureRecognizer == scrollView?.panGestureRecognizer
    }

The issue is I've broken the table's reordering controls:

重新排序控制手势在 UITableView 上不起作用

The reordering gesture starts successfully, but then my custom pan gesture kicks in and breaks it.

I can fix this by requiring other gestures to fail before my custom gesture is recognized:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
             shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true  // I need to be more specific in here
}

But this is too broad and other things break when I leave this here. I need a way to just target the reorder control's gesture, but I can't find any way to check for it.

Does anyone know how to get a reference to the reorder control's gesture? Or can anyone suggest a different approach to resolve this conflict? Any help would be much appreciated!

Try adding this to your UIPanGestureRecognizer :

panGestureRecognizer.cancelsTouchesInView = false

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