UITableView contentInset does not update when keyboard interactively declines

Update

I found that in my many refactoring I inherited from UIViewControllerinstead UITableViewController, so I was missing some kind of automatic behaviors that it UITableViewControllerprovides. However, I still need to manually handle scroll inserts when the keyboard was fired interactively. See My updated answer.


I am trying to imitate iMessage by how the keyboard deviates when the user drags it to the bottom of the screen. I have a job with one small visual problem that listens to me.

When the keyboard is dragged from the screen, the scroll indicators do not change correctly, that is, until it is completely removed.

I use keyboard notifications to tell me when the keyboard appeared to enlarge the content and scroll the inserts to the height of the keyboard. It seems I don’t have to do anything when the keyboard was fired, as the inserts look right when they were. However, when rejecting interactively, I cannot update the inserts during the drag event.

To illustrate the problem, the first image shows that the content scrolls on top of the screen due to the space occupied by the keyboard; the user scrolls to the last row in the table:

Keyboard displayed, content scrolled to bottom

. , . , , , , , . , iMessage.

Keyboard being dismissed

, , , , UIToolBar (iOS 8.3) :

override var inputAccessoryView: UIView {
    return toolbar
}

override func canBecomeFirstResponder() -> Bool {
    return true
}

func willShowKeyboard(notification: NSNotification) {
    let keyboardFrame = notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
    tableView.contentInset.bottom = keyboardFrame.CGRectValue().height
    tableView.scrollIndicatorInsets.bottom = keyboardFrame.CGRectValue().height
}
+4
1

Update

UITableViewController , scrollViewDidScroll() ( ) .

override func scrollViewDidScroll(scrollView: UIScrollView) {

    if !keyboardShowing {
        return
    }

    let toolbarFrame = toolbar.convertRect(toolbar.frame, toView: nil)

    tableView.scrollIndicatorInsets.bottom = view.bounds.height - toolbarFrame.minY
    tableView.contentInset.bottom = view.bounds.height - toolbarFrame.minY
}

. , , . , .

func didShowKeyboard(notification: NSNotification) {
    let keyboardFrame = notification.userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue
    let keyboardHeight = keyboardFrame.CGRectValue().height

    tableView.contentInset.bottom = keyboardHeight
    tableView.scrollIndicatorInsets.bottom = keyboardHeight

    keyboardShowing = true
}

func didHideKeyboard(notification: NSNotification) {
    keyboardShowing = false
}

func scrollViewDidScroll(scrollView: UIScrollView) {

    if !keyboardShowing {
        return
    }

    let toolbarFrame = view.convertRect(toolbar.frame, fromView: toolbar)

    tableView.scrollIndicatorInsets.bottom = view.bounds.height - toolbarFrame.minY
    tableView.contentInset.bottom = view.bounds.height - toolbarFrame.minY
}
0

All Articles