IQKeboard manager leaving lot of top space when going to previous textfield

303 views Asked by At

I have list of textfields inside stackviews which are again embedded in scrollview. For keyboard handling I've used IQKeyboard manager it works fine. Although there is a special case when it leaves too much space on top. Below is my current UI structure

enter image description here Now suppose my cursor is on second textfield and I scrolled up till the end, now if I tap on the previous button, the focus does comes on first textfield but it also scrolls it down to show it just above keyboard like below screenshot. My actual expectation is, it should focus on first textfield like now but it should keep the top space to come down constant and shouldn't leave this much space.

enter image description here

From codewise I just enabled the IQKeyboardManager from AppDelegate. No other code is added for this.

 IQKeyboardManager.shared.enable = true

Any help is appreciated

1

There are 1 answers

0
Francis F On

Try updating scroll view content offset on textFieldDidEndEditing like below

  func textFieldDidEndEditing(_ textField: UITextField) {
        scrollview.setContentOffset(CGPoint.zero, animated: false)
    }