Keep your views visible when keyboard is being shown.
- iOS 8.0 +
- Swift 5.0 +
Add following to your Cartfile
and run Carthage update
.
github "DanisFabric/FollowKeyboard"
add FollowKeyboard.swift
to your project.
let fk = FollowKeyboard()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
fk.followKeyboard(withAnimations: { [unowned self] (keyboardFrame, duration, type) in
switch type {
case .show:
self.bottomBar.frame = self.bottomBar.frame.offsetBy(dx: 0, dy: -keyboardFrame.height)
case .hide:
self.bottomBar.frame = self.bottomBar.frame.offsetBy(dx: 0, dy: keyboardFrame.height)
}
}, completionBlock: nil)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
fk.unfollowKeyboard()
}
let fk = FollowKeyboard()
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
fk.followKeyboard(withAnimations: { (keyboardFrame, duration, type) in
switch type {
case .show:
self.barBottomConstaint.constant += keyboardFrame.height
self.view.layoutIfNeeded()
case .hide:
self.barBottomConstaint.constant -= keyboardFrame.height
self.view.layoutIfNeeded()
}
}, completionBlock: nil)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
fk.unfollowKeyboard()
}
You'd better add the code to
viewWillAppear:
andviewDidDisappear
contact me: [email protected]