Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created March 20, 2020 07:57
Show Gist options
  • Save vialyx/bd72fd169eca0948e0d23afa52eb1ed8 to your computer and use it in GitHub Desktop.
Save vialyx/bd72fd169eca0948e0d23afa52eb1ed8 to your computer and use it in GitHub Desktop.
final class ViewController: UIViewController {
let keyboard = KeyboardObserver()
weak var firstRespounder: UIView?
override func viewDidLoad() {
super.viewDidLoad()
keyboard.handler = {
[weak self] state in
switch state {
case .show(let rect):
let y = self!.view.bounds.height - rect.height - self!.firstRespounder!.convert(self!.firstRespounder!.frame, to: self?.view!).maxY
if y > 0 {
return
}
self?.view.transform = CGAffineTransform.identity.translatedBy(x: 0, y: y)
default:
self?.view.transform = .identity
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment