1

I have a swift handler that detects when a user swipes a view. If they swipe the view with their finger, I want the view to follow their finger until a certain point, then slow down and lag behind the finger. (For example when you drag a tableView past its top, and it "lags" behind your finger). Is there a formula I can use to do this?

My code so far (its in the swipe action function)

 // Transform if it is going left
 if (translation.x <= 0) {
   // If reply has not been triggered yet, match view position to finger position
   if (!replyTriggered) {
     self.transform = CGAffineTransform(translationX: translation.x, y: 0)
   }
   // If it has been triggered, make movement less and less
   else {
     let translationX = "????"
     self.transform = CGAffineTransform(translationX: translationX, y: 0)
   }
}
  • Check out this link [Follow Finger](https://stackoverflow.com/questions/25503537/swift-uigesturerecogniser-follow-finger), hope you can make something off it. cheers – OsamaD Jul 16 '19 at 14:52

1 Answers1

1

This is how i ended up doing it (after moving to react native, but the formula should still be the same)

var translateValue = 800*Math.log10((gestureState.dx/800)+1);