func keyboardWillShow(notification: NSNotification) {
let userInfo = notification.userInfo as NSDictionary!
let frameNew = (userInfo[UIKeyboardFrameEndUserInfoKey] as NSValue).CGRectValue()
let insetNewBottom = tableView.convertRect(frameNew, fromView: nil).height
let insetOld = tableView.contentInset
let insetChange = insetNewBottom - insetOld.bottom
let overflow = tableView.contentSize.height - (tableView.frame.height-insetOld.top-insetOld.bottom)
let duration = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as NSNumber).doubleValue
let animations: (() -> Void) = {
if !(self.tableView.tracking || self.tableView.decelerating) {
// Move content with keyboard
if overflow > 0 { // scrollable before
self.tableView.contentOffset.y += insetChange
if self.tableView.contentOffset.y < -insetOld.top {
self.tableView.contentOffset.y = -insetOld.top
}
} else if insetChange > -overflow { // scrollable after
self.tableView.contentOffset.y += insetChange + overflow
}
}
}
if duration > 0 {
let options = UIViewAnimationOptions(UInt((userInfo[UIKeyboardAnimationCurveUserInfoKey] as NSNumber).integerValue << 16)) // http://stackoverflow.com/a/18873820/242933
UIView.animateWithDuration(duration, delay: 0, options: options, animations: animations, completion: nil)
} else {
animations()
}
}
I have a toolbar, and when the textview in the toolbar is selected, the keyboard appears under it. The toolbar then slides up, but just to above the keyboard, but it still hides beneath the new suggestions feature above the keyboard in one of the recent iOS updates.
How do I make sure that the toolbar stays above the word suggestions?