let pan = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture))

        self.addGestureRecognizer(pan)


 guard gestureRecognizer.view != nil else {return}

        

        let currentPoint = gestureRecognizer.location(in: gestureRecognizer.view!)



if gestureRecognizer.state == UIGestureRecognizerState.began {

            startingPoint = currentPoint


   }

        

        if gestureRecognizer.state == UIGestureRecognizerState.ended {

            endedPoint = currentPoint


     if endedPoint.y < startingPoint.y {

                isUPscrolling = true

            } else { isUPscrolling = false }

            Scrolling()

        }



    fileprivate func Scrolling() {

        

        let distance = CGPoint(x: 0, y: fabs(endedPoint.y - startingPoint.y)).y

        

        if isUPscrolling {

            if distance > 30 {

                self.setContentOffset(CGPoint(x:0, y:444), animated: true

            } else {

                self.setContentOffset(CGPoint(x: 0, y: self.contentOffset.y + distance), animated: true)

            }

        } else {

            if (self.contentOffset.y - distance) < 0 {

                self.setContentOffset(CGPoint(x: 0, y: 0), animated: true)

            } else {

                self.setContentOffset(CGPoint(x: 0, y: self.contentOffset.y - distance), animated: true)

            }

        }

    }

+ Recent posts