JoniVR / VerticalCardSwiper

A marriage between the Shazam Discover UI and Tinder, built with UICollectionView in Swift.
MIT License
1.4k stars 101 forks source link

[Question] how to forbid the sliding gestures in subview #59

Closed EternalChildren closed 5 years ago

EternalChildren commented 5 years ago

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?

JoniVR commented 5 years ago

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

EternalChildren commented 5 years ago

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?