Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The card gets stuck at the top of the view when sliding quickly #153

Open
MingYik opened this issue Jan 30, 2024 · 0 comments
Open

The card gets stuck at the top of the view when sliding quickly #153

MingYik opened this issue Jan 30, 2024 · 0 comments

Comments

@MingYik
Copy link

MingYik commented Jan 30, 2024

The card gets stuck at the top of the view when sliding quickly, Here is the fix code:

@objc func handlePan(_ recognizer: UIPanGestureRecognizer) {

        guard let swipeableView = swipeableView else { return }
        let translation = recognizer.translation(in: containerView)
        let location = recognizer.location(in: containerView)
        let velocity = recognizer.velocity(in: containerView)
        let movement = Movement(location: location, translation: translation, velocity: velocity)
        switch recognizer.state {
        case .began:
            guard case .snapping(_) = state else { return }
            state = .moving(location)
            swipeableView.didStart?(view, location)
        case .changed:
            guard case .moving(_) = state else { return }
            state = .moving(location)
            swipeableView.swiping?(view, location, translation)
        case .ended, .cancelled:
            guard case .moving(_) = state else { return }
            if swipeableView.shouldSwipeView(view, movement, swipeableView) {
                let directionVector = CGVector(point: translation.normalized * max(velocity.magnitude, swipeableView.minVelocityInPointPerSecond))
                // The reason is that fast sliding will have a directionVector of Nan, and the relevant judgment is added here
                guard directionVector.dx.isNaN || directionVector.dy.isNaN else {
                    state = .swiping(location, directionVector)
                    swipeableView.swipeView(view, location: location, directionVector: directionVector)
                    swipeableView.didEnd?(view, location)
                    return
                }
            }
            state = snappingStateAtContainerCenter()
            swipeableView.didCancel?(view)
            swipeableView.didEnd?(view, location)
        default:
            break
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant