Advertisement
KY1VSTAR

#2

May 25th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.31 KB | None | 0 0
  1. private class func handlePan(_ recognizer: UIPanGestureRecognizer) {
  2.         switch recognizer.state {
  3.         case .began:
  4.             panStartY = recognizer.location(in: appDelegateWindow).y
  5.             panPeviousY = panStartY
  6.             panShouldIgnoreEndedState = true
  7.             keyboardStartY = keyboardFrame.origin.y
  8.             textEffectsView.window!.isUserInteractionEnabled = false
  9.             remoteView?.window?.isUserInteractionEnabled = false
  10.         case .changed:
  11.             let distance = keyboardStartY - panStartY
  12.             let currentY = recognizer.location(in: appDelegateWindow).y
  13.             let deltaY = currentY - distance - panStartY
  14.             let adjustment = min(max(keyboardStartY + deltaY, calculatedKeyboardStartY), appDelegateWindow.frame.height)
  15.             keyboardFrame.origin.y = adjustment
  16.             panIsMovingDown = currentY > panPeviousY
  17.             panPeviousY = currentY
  18.             panShouldIgnoreEndedState = deltaY <= 0
  19.         case .ended:
  20.             if panShouldIgnoreEndedState {
  21.                 return
  22.             }
  23.             panGestureRecognizer.isEnabled = false
  24.             textEffectsView.window!.isUserInteractionEnabled = true
  25.             remoteView?.window?.isUserInteractionEnabled = true
  26.            
  27.             let initialFrame = keyboardFrame
  28.             var finalFrame = initialFrame
  29.             finalFrame.origin.y = panIsMovingDown ? appDelegateWindow.frame.height : calculatedKeyboardStartY
  30.            
  31.             UIView.animate(withDuration: defaultAnimationDuration, delay: 0, options: defaultAnimationCurve, animations: {
  32.                 keyboardFrame = finalFrame
  33.             }, completion: { _ in
  34.                 panGestureRecognizer.isEnabled = true
  35.                
  36.                 delegateKeyboardDidHide(KSKeyboardInfo(initialFrame: initialFrame, finalFrame: finalFrame))
  37.                
  38.                 textEffectsView.isHidden = true
  39.                 remoteView?.window?.isHidden = true
  40.                 appDelegateWindow.endEditing(true)
  41.             })
  42.         case .cancelled, .failed:
  43.             textEffectsView.window!.isUserInteractionEnabled = true
  44.             remoteView?.window?.isUserInteractionEnabled = true
  45.             keyboardFrame.origin.y = calculatedKeyboardStartY
  46.         default:
  47.             ()
  48.         }
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement