Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect keyboard frame changes when dismiss the keyboard interactively?

Consider this scenario, I have a textview with keyboard Dismiss interactively set in storyboard, so when user scroll down and able to dismiss keyboard interactively. I have constraints on the textview to bottom to make sure it is always fully displayed on the view.

Current problem is, when user gradually scroll down to dismiss the keyboard, I can not detect the keyboard frame changes. I tried UIKeyboardWillHideNotification and UIKeyboardWillChangeFrameNotification, they were only called after the keyboard dismissed.

So my question is, how can we detect keyboard frame changes simultaneously when dismiss the keyboard interactively?

like image 517
air_bob Avatar asked Oct 27 '15 08:10

air_bob


2 Answers

If you want to observe keyboard frame changes even when the keyboard is being dragged you can use this: https://github.com/brynbodayle/BABFrameObservingInputAccessoryView

Basically you create a placeholder input view for keyboard (which sticks to the keyboard all the time, even while dragging) and you observe it's frame changes. Those changes are being returned in a block, so you get current frame of the keyboard all the time.

like image 123
haluzak Avatar answered Nov 07 '22 02:11

haluzak


You shouldn't change the textView height to fit all view. Instead - you should change contentInset field so your textView will stay the same height and you won't have to bother about tracking frame of the interactive keyboard. See answer here: How do I scroll the UIScrollView when the keyboard appears?

like image 39
quarezz Avatar answered Nov 07 '22 02:11

quarezz