简体   繁体   中英

IQKeyboardManager: is it possible to change the distance between the UITextField and the Keyboard?

This is the default view without the keyboard

This is what happens when the keyboard shows up

I am using the IQKeyboardManagerSwift and would like to reduce the distance between the keyboard and the textfield. I have already tried changing keyboardDistanceFromTextField, but it didn't change anything, like this:

IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.keyboardDistanceFromTextField = 10

And yes, the keyboard manager should be working because I already use it's other functions like the IQKeyboardManager.shared.enableAutoToolbar = false

I have tried the same demo and at my end it showing properly. Please check在此处输入图像描述

Only this much code I have done for the keyboard have a look into this.

AppDelegate.swift

        IQKeyboardManager.shared.enable = true
        IQKeyboardManager.shared.shouldResignOnTouchOutside = true
        IQKeyboardManager.shared.shouldShowToolbarPlaceholder = false
        IQKeyboardManager.shared.enableAutoToolbar = false

May be the issue is related to your constraint please check your constraint as well. If this stuff not help you then please show your constraint applied.

I fixed the problem by checking if the TextField is active with

func textFieldDidBeginEditing(_ textField: UITextField) {
        heightConstraint.constant = 25 
        heightConstraint2.constant = 10
        buttonHeightConstraint.constant = 11
}

And if the TextField is active - it changes the constraints that I declared as Outlets. When the TextField isn't active, it changes the constraints back to the previous values:

func textFieldDidEndEditing(_ textField: UITextField) {
        heightConstraint.constant = 60
        heightConstraint2.constant = 20
        buttonHeightConstraint.constant = 20
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM