PhotoEditor+Keyboard.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // PhotoEditor+Keyboard.swift
  3. // Pods
  4. //
  5. // Created by Mohamed Hamed on 6/16/17.
  6. //
  7. //
  8. import Foundation
  9. import UIKit
  10. extension PhotoEditorViewController {
  11. @objc func keyboardDidShow(notification: NSNotification) {
  12. if isTyping {
  13. doneButton.isHidden = false
  14. colorPickerView.isHidden = false
  15. hideToolbar(hide: true)
  16. }
  17. }
  18. @objc func keyboardWillHide(notification: NSNotification) {
  19. isTyping = false
  20. doneButton.isHidden = true
  21. hideToolbar(hide: false)
  22. }
  23. @objc func keyboardWillChangeFrame(_ notification: NSNotification) {
  24. if let userInfo = notification.userInfo {
  25. let endFrame = (userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue
  26. let duration:TimeInterval = (userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0
  27. let animationCurveRawNSN = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as? NSNumber
  28. let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIView.AnimationOptions.curveEaseInOut.rawValue
  29. let animationCurve:UIView.AnimationOptions = UIView.AnimationOptions(rawValue: animationCurveRaw)
  30. if (endFrame?.origin.y)! >= UIScreen.main.bounds.size.height {
  31. self.colorPickerViewBottomConstraint?.constant = 0.0
  32. } else {
  33. self.colorPickerViewBottomConstraint?.constant = endFrame?.size.height ?? 0.0
  34. }
  35. UIView.animate(withDuration: duration,
  36. delay: TimeInterval(0),
  37. options: animationCurve,
  38. animations: { self.view.layoutIfNeeded() },
  39. completion: nil)
  40. }
  41. }
  42. }