mac-gallagher / Shuffle

🔥 A multi-directional card swiping library inspired by Tinder
MIT License
912 stars 139 forks source link

how can i use scrollview inside swipecard? #143

Open Sabellus opened 3 years ago

Sabellus commented 3 years ago

@mac-gallagher any ideas?

mac-gallagher commented 3 years ago

I haven't tried this myself yet, but you will need to manage the gesture recognizers yourself. See https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/coordinating_multiple_gesture_recognizers

mac-gallagher commented 3 years ago

Will leave this open in case anyone else has tried this and can offer some help

BayramInanc commented 2 years ago

any update?

BayramInanc commented 2 years ago

Hi,

I added scrollview inside swipe card. The code is like, I added only difference parts.

1-) **TinderCardContentView*****

private func initialize() { let scrollViewPanGesture = UIPanGestureRecognizer() scrollViewPanGesture.addTarget(self, action:#selector(self.handle(gesture:))) scrollViewPanGesture.delegate = self scrollView.addGestureRecognizer(scrollViewPanGesture) ....... ....... .... }

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

**TinderCardContentView*****

2-) **SwipeView*****

public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return false } **SwipeView*****

3-) **SwipeCardStack*****

open var shouldRecognizeVerticalDrag: Bool = false

override open func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { guard let topCard = topCard, topCard.panGestureRecognizer == gestureRecognizer else { return super.gestureRecognizerShouldBegin(gestureRecognizer) }

    let velocity = topCard.panGestureRecognizer.velocity(in: self)
    let translation = topCard.panGestureRecognizer.translation(in: topCard.superview)
    if abs(velocity.x) > 0 {
        if abs(translation.x) > 1{
            return shouldRecognizeHorizontalDrag
        }else{
            return shouldRecognizeVerticalDrag
        }
    }
    else{
        return false
    }

}

**SwipeCardStack*****