Within a UIViewController
I've set
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive
.
This is great because the user can drag the keyboard down from the tableview.
However, the tableview maintains it's current height when dragging down the keyboard. This looks odd because it leaves empty space between the keyboard and the scrollview.
How can I persistently track the frame of the keyboard so I may resize the tableview as the user drags the keyboard? I've tried using UIKeyboardWillChangeFrameNotification
but that seems to only get called after the user finishes dragging.
Your table view shouldn't change its height to accommodate the keyboard.
Instead, the keyboard should be presented overtop of the table view, and you should adjust the contentInset
and scrollIndicatorInsets
properties on the table view so that the lower table content is not obscured by the keyboard. You need to update the scroll insets whenever the keyboard is presented or dismissed.
You don't have to do anything special while the keyboard is dismissed interactively, because the table content should already scroll down as the keyboard moves out of view.
I'd rather this not be the accepted answer, but for those of you out there also having trouble with this here's what worked for me.
Create a custom subclass of UIView.
In the subclass's willMoveToSuperview:
method, add a KVO observer to the superview's center
on iOS 8 and frame
on lesser versions of iOS (remember to remove the old observer, you may want to use an instance variable to track this).
In your view controller add a 0.0 height input accessory view to the view controller via inputAccessoryView
class override. Use your custom UIView
subclass for this.
Back in the subclass, in observeValueForKeyPath:...
, capture the frame
of the view's superview, this should be the frame of the UIKeyboard
.
Use NSNotificationCenter
or some other means to then pass this frame
back to your view controller for processing.
It's a pretty painful process and not guaranteed to work in future versions of iOS. There are likely a ton of edge cases that will pop up later since I just built this, but it's a good start. If anyone has a better idea I'll happily mark your answer as correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With