Keep your views visible when keyboard is being shown.
- iOS 8.0 +
- Swift 2.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: { (keyboardFrame, duration, type) -> Void in
switch type {
case .Show:
self.bottomBar.frame = CGRectOffset(self.bottomBar.frame, 0, -keyboardFrame.height)
case .Hide:
self.bottomBar.frame = CGRectOffset(self.bottomBar.frame, 0, keyboardFrame.height)
}
}) { (finished) -> Void in
}
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
fk.unfollowKeyboard()
}
let fk = FollowKeyboard()
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
fk.followKeyboard(withAnimations: { (keyboardFrame, duration, type) -> Void in
switch type {
case .Show:
self.barBottomConstaint.constant += keyboardFrame.height
self.view.layoutIfNeeded()
case .Hide:
self.barBottomConstaint.constant -= keyboardFrame.height
self.view.layoutIfNeeded()
}
}) { (finished) -> Void in
}
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
fk.unfollowKeyboard()
}
You'd better add the code to
viewWillAppear:
andviewWillDisappear