ios - UITableView contentInset not updating when keyboard interactively dismissed -
ios - UITableView contentInset not updating when keyboard interactively dismissed -
update
i found in many refactorings inheriting uiviewcontroller
instead of uitableviewcontroller
, missing automatic behaviours uitableviewcontroller
provides. however, still needed manually handle scroll views insets when keyboard beingness interactively dismissed. see updated answer.
i trying emulate imessage in how keyboard dismissed when user drags bottom of screen. have working 1 little visual issue that's bugging me.
as keyboard dragged off screen scroll indicators not resize correctly - until has been dismissed.
i utilize keyboard notifications tell me when keyboard has appeared increment content , scroll insets height of keyboard. seems didn't need when keyboard has been dismissed insets appear right when has been. when dismissing interactively can't update insets during dragging event.
to illustrate issue, first image shows content has scrolled off top of screen due space beingness occupied keyboard; user has scrolled lastly row in table:
here, keyboard beingness dismissed , off-screen. notice how scroll indicators wrong size. of content on screen indicators should stretching, however, happens keyboard moves down, scroll indicators move , not stretch. not happens in imessage.
i think i'm doing pretty standard, i'm creating uitoolbar (ios 8.3) , overriding these methods in view controller:
override var inputaccessoryview: uiview { homecoming toolbar } override func canbecomefirstresponder() -> bool { homecoming true } func willshowkeyboard(notification: nsnotification) { allow keyboardframe = notification.userinfo![uikeyboardframeenduserinfokey] as! nsvalue tableview.contentinset.bottom = keyboardframe.cgrectvalue().height tableview.scrollindicatorinsets.bottom = keyboardframe.cgrectvalue().height }
update
after switching uitableviewcontroller
, found implementation of scrollviewdidscroll()
(along other methods in original solution below) did trick of dynamically resizing insets when keyboard interactively dismissed.
override func scrollviewdidscroll(scrollview: uiscrollview) { if !keyboardshowing { homecoming } allow toolbarframe = toolbar.convertrect(toolbar.frame, toview: nil) tableview.scrollindicatorinsets.bottom = view.bounds.height - toolbarframe.miny tableview.contentinset.bottom = view.bounds.height - toolbarframe.miny }
i've managed accomplish same effect. i'm not sure if correct method, works nicely. i'll interested know other solutions there might be.
func didshowkeyboard(notification: nsnotification) { allow keyboardframe = notification.userinfo![uikeyboardframeenduserinfokey] as! nsvalue allow 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 { homecoming } allow toolbarframe = view.convertrect(toolbar.frame, fromview: toolbar) tableview.scrollindicatorinsets.bottom = view.bounds.height - toolbarframe.miny tableview.contentinset.bottom = view.bounds.height - toolbarframe.miny }
ios uitableview scroll uiscrollview keyboard
Comments
Post a Comment