IdleHandsApps / IHKeyboardAvoiding

IHKeyboardAvoiding is an elegant solution for keeping any UIView visible when the keyboard is being shown - no UIScrollView required!
MIT License
1.41k stars 150 forks source link

Issue when switching from keyboard with suggestions to keyboard without #59

Open mahavi opened 5 years ago

mahavi commented 5 years ago

There is an issue when switching from keyboard with suggestions on one screen to keyboard without suggestions on another screen: avoidview offset is calculated incorrectly and textfiled is placed under keyboard.

How to reproduce: I have created sample project to reproduce this issue: https://github.com/maks-g/IHKeyboardAvoidingIssueSample

Also, you can check recorded video: https://github.com/maks-g/IHKeyboardAvoidingIssueSample/blob/master/issue_sample.mp4

alexanderkhitev commented 5 years ago

I also faced with this bug

alexanderkhitev commented 5 years ago

hey @maks-g ! Did you solve this issue?

mahavi commented 5 years ago

nope :(

lemoncello commented 1 year ago

A bit late, but found a fix for this. Also, happens when toggling between the emoji and the Text keyboard. Just add these lines:

var displacedOriginToWindow = triggerView.convert(triggerView.bounds, to: nil)
                                    displacedOriginToWindow.origin.y -= displacement

                                    if (keyboardFrame.intersects(displacedOriginToWindow) && keyboardHeightDiff != 0) {
                                        displacement = keyboardFrame.origin.y - displacedOriginToWindow.maxY - keyboardFrame.intersection(displacedOriginToWindow).height
                                    }

just below the these constraint conditions (lines ~162):

if let secondItem = constraint.secondItem as? NSObject,
                                        secondItem == self.avoidingView! && (constraint.secondAttribute == .centerY || constraint.secondAttribute == .top || constraint.secondAttribute == .bottom) {

Then, the displacement is adjusted to the displacement given the case the keyboard IS NOT hiding but resizing instead.