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
keyboardAreaLayoutGuideof your view.
chatBarView.bottomAnchor.constraint(equalTo: view.keyboardAreaLayoutGuide.topAnchor)- You can also observe the change of the keyboard
view.keyboardObserver.keyboardHeightChange
.sink{ change inprint(change)}- You can invalidate the observer at any time.
overridefunc viewWillAppear(_ animated:Bool){
super.viewWillAppear(animated)
view.keyboardObserver.validate()}overridefunc 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.
