This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| class KeyboardAppearListener { | |
| private var showKeyboard: NotificationToken? | |
| private var hideKeyboard: NotificationToken? | |
| private weak var viewController: UIViewController? | |
| private var windowSafeArea: CGFloat = 0 | |
| private var windowsSafeAreaWereAdded = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let duration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] | |
| .flatMap { $0 as? Double } ?? 0.25 | |
| if duration > 0 { | |
| let curve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] | |
| .flatMap { $0 as? Int } | |
| .flatMap { UIView.AnimationCurve(rawValue: $0) } ?? .easeInOut | |
| UIViewPropertyAnimator(duration: duration, curve: curve) { | |
| viewController.view.layoutIfNeeded() | |
| } | |
| .startAnimation() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let windowSafeArea: CGFloat = windowsSafeAreaWereAdded ? 0 : viewController.view.safeAreaInsets.bottom - viewController.additionalSafeAreaInsets.bottom | |
| viewController.additionalSafeAreaInsets.bottom += beginKeyboardBounds.origin.y - endKeyboardBounds.origin.y - windowSafeArea | |
| windowsSafeAreaWereAdded = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| viewController.additionalSafeAreaInsets.bottom += beginKeyboardFrame.origin.y - endKeyboardFrame.origin.y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| guard | |
| let viewController = viewController, | |
| let userInfo = notification.userInfo, | |
| let beginKeyboardFrame = userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? CGRect, | |
| let endKeyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect, | |
| endKeyboardFrame != beginKeyboardFrame | |
| else { | |
| return | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class KeyboardAppearListener { | |
| private var showKeyboard: NotificationToken? | |
| private var hideKeyboard: NotificationToken? | |
| private weak var viewController: UIViewController? | |
| init( | |
| _ viewController: UIViewController, | |
| notificationCenter: NotificationCenter = .default) { | |
| self.viewController = viewController | |
| showKeyboard = notificationCenter.observe( | |
| name: UIResponder.keyboardWillShowNotification) { [weak self] (notification) in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ViewController: UIViewController { | |
| //Register for notification ... | |
| private func addjustSafeAreaTo(keyboardFrame: CGRect) { | |
| view.safeAreaInsets.bottom = keyboardFrame.height | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UIKeyboardAnimationCurveUserInfoKey: 7 | |
| UIKeyboardAnimationDurationUserInfoKey: 0.25 | |
| UIKeyboardBoundsUserInfoKey: NSRect: {{0, 0}, {820, 337}} | |
| UIKeyboardCenterBeginUserInfoKey: NSPoint: {410, 1319.5} | |
| UIKeyboardCenterEndUserInfoKey: NSPoint: {410, 1011.5} | |
| UIKeyboardFrameBeginUserInfoKey: NSRect: {{0, 1180}, {820, 279}} | |
| UIKeyboardFrameEndUserInfoKey: NSRect: {{0, 843}, {820, 337}} | |
| UIKeyboardIsLocalUserInfoKey: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| UIResponder.keyboardWillShowNotification | |
| UIResponder.keyboardDidShowNotification | |
| UIResponder.keyboardWillHideNotification | |
| UIResponder.keyboardDidHideNotification |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ $# -lt 2 ]; then | |
| echo "format: git_cleanup <repo name> [-x/--expunge <directory 1> -l/--keeplatest <directory 2> ...]" | |
| exit | |
| fi | |
| PROJ="$1" | |
| shift |
NewerOlder