This file contains 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
final class ViewController: UIViewController { | |
@IBOutlet weak var scrollView: UIScrollView! | |
private var keyboardObserver: KeyboardObserver? | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
keyboardObserver = KeyboardObserver(changeHandler: { [weak self] (info) in | |
guard let self = self else { return } | |
switch info.event { | |
case .willShow: | |
self.scrollView.contentInset.bottom = info.endFrame.height | |
case .willHide: | |
self.scrollView.contentInset.bottom = 0 | |
default: | |
break | |
} | |
}) | |
} | |
override func viewDidDisappear(_ animated: Bool) { | |
super.viewDidDisappear(animated) | |
keyboardObserver = nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment