Guest User

Untitled

a guest
Feb 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. var startingFrame: CGRect?
  2. @objc func acknowledgeSwiped(sender: UIPanGestureRecognizer) {
  3. if let sliderView = sender.view {
  4. let translation = sender.translation(in: swipeView)
  5. switch sender.state {
  6. case .began:
  7. startingFrame = swipeImage.frame
  8. fallthrough
  9. case .changed:
  10. if let startFrame = startingFrame {
  11.  
  12. var movex = translation.x
  13. if movex < -startFrame.origin.x { movex = -startFrame.origin.x }
  14.  
  15. let xMax = swipeView.frame.width - startFrame.origin.x - startFrame.width
  16. if movex > xMax {
  17. movex = xMax
  18. acknowledge()
  19. }
  20.  
  21. var movey = translation.y
  22. if movey < -startFrame.origin.y { movey = -startFrame.origin.y }
  23.  
  24. let yMax = swipeView.frame.height - startFrame.origin.y - startFrame.height
  25. if movey > yMax {
  26. movey = yMax
  27.  
  28. }
  29.  
  30. sliderView.transform = CGAffineTransform(translationX: movex, y: movey)
  31. }
  32. default: // .ended and others:
  33. UIView.animate(withDuration: 0.1, animations: {
  34. sliderView.transform = CGAffineTransform.identity
  35. })
  36. }
  37. }
  38. }
Add Comment
Please, Sign In to add comment