Advertisement
KY1VSTAR

#6

May 25th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.49 KB | None | 0 0
  1. @objc private func handlePanGesture(_ recognizer: UIPanGestureRecognizer) {
  2.         switch recognizer.state {
  3.         case .began:
  4.             panStartPoint = recognizer.translation(in: subContentView)
  5.             startingLeftConstraingConstant = subContentLeftConstraint.constant
  6.         case .changed:
  7.             let currentPoint = recognizer.translation(in: subContentView)
  8.             let deltaX = currentPoint.x - panStartPoint.x
  9.            
  10.             let panningLeft = currentPoint.x < panStartPoint.x
  11.  
  12.             if startingLeftConstraingConstant == 0 {
  13.                 //была закрыта, сейчас открывается
  14.                 if panningLeft {
  15.                     subContentLeftConstraint.constant = max(deltaX, -sideMenuWidth)
  16.                 } else {
  17.                     subContentLeftConstraint.constant = min(deltaX, 0)
  18.                 }
  19.             } else {
  20.                 //хотя бы частично была открыта
  21.                 let adjustment = startingLeftConstraingConstant + deltaX
  22.                 if panningLeft {
  23.                     subContentLeftConstraint.constant = max(adjustment, -sideMenuWidth)
  24.                 } else {
  25.                     subContentLeftConstraint.constant = min(adjustment, 0)
  26.                 }
  27.             }
  28.         case .ended:
  29.             if startingLeftConstraingConstant == 0 {
  30.                 let neededConstantToOpen = -sideMenuWidth / 6
  31.                 if subContentLeftConstraint.constant <= neededConstantToOpen {
  32.                     _setSideMenuHidden(false, animated: true, notifyDelegate: true)
  33.                 } else {
  34.                     _setSideMenuHidden(true, animated: true, notifyDelegate: false)
  35.                 }
  36.             } else {
  37.                 let neededConstantToClose = -sideMenuWidth * 5 / 6
  38.                 if subContentLeftConstraint.constant >= neededConstantToClose {
  39.                     _setSideMenuHidden(true, animated: true, notifyDelegate: true)
  40.                 } else {
  41.                     _setSideMenuHidden(false, animated: true, notifyDelegate: false)
  42.                 }
  43.             }
  44.         case .cancelled:
  45.             //delegate?.messageItemCellDidEndPan(self)
  46.             if startingLeftConstraingConstant == 0 {
  47.                 _setSideMenuHidden(true, animated: true, notifyDelegate: false)
  48.             } else {
  49.                 _setSideMenuHidden(false, animated: true, notifyDelegate: false)
  50.             }
  51.         default:
  52.             break
  53.         }
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement