JoniVR / VerticalCardSwiper

A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] how to forbid the sliding gestures in subview

EternalChildren opened this issue · comments

New Issue Checklist

Question

i have a view struct likes

JPMain(extends VerticalCardSwiperDelegate)  -->  JPCell(CardCell)  -->  Canvas(UIView in JPCell)

i try to control the cell gesture, hope to forbid the sliding up or down. then i find a nice solution that modify the below function

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool 

but i failed. so i want to know how to forbid the sliding gestures for VerticalCardSwiper. looks like it’s here

extension VerticalCardSwiper: UIGestureRecognizerDelegate

expected:
i want the VerticalCardSwiper can't slide up or down when i handle some gesture in Canvas
Can you help me?

Have you tried using cardSwiper.verticalCardSwiperView.isScrollEnabled = false?
Or are the gesturerecognizers interfering?

i have solve it by the below way

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
        let superview = self.superview as? VerticalCardSwiperView
        superview?.isScrollEnabled = true
        
        if let target = touch.view {
            if target.isDescendant(of: canvas) {
                superview?.isScrollEnabled = false
                return false
            }
        }
        return true
    }

But i am sure it's the best way because it should set isScrollEnabled = true lots of times
what's the gesture recognizers interfering?