Level : WORDPRESS BOOK LINKEDIN PATENT Send Mail 동냥하기 hajunho.com

반응형

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)

            }

        }

    }

반응형
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기