Provides a reactive way to observe the changes of the keyboard's frame using Swift Combine.
- iOS 13.0+
- Swift 5.10
- Attach your view's anchor to the
keyboardAreaLayoutGuide
of your view.
chatBarView.bottomAnchor.constraint(equalTo: view.keyboardAreaLayoutGuide.topAnchor)
- You can also observe the change of the keyboard
view.keyboardObserver.keyboardHeightChange
.sink { change in
print(change)
}
- You can invalidate the observer at any time.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
view.keyboardObserver.validate()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
view.keyboardObserver.invalidate()
}
Add the below line to your Package.swift file as a dependency:
.package(url: "https://github.com/DouKing/KeyboardObserver.git", .upToNextMajor(from: "1.0"))
Normally you'll want to depend on the KeyboardObserver
target:
.product(name: "KeyboardObserver", package: "KeyboardObserver")
KeyboardObserver is under MIT license.