How to hide toolbar in IQKeyboardManager iOS Swift 3

I use the IQKeyboardManger library to scroll through text fields at the beginning of keyboard input, but I do not want to display the default toolbars from my library. Below is the code I used.

override func viewDidLoad() {
        super.viewDidLoad()

        self.chatTextField.inputAccessoryView = [[UIView alloc] init];  //This will remove toolbar which have done button.

        self.chatTextField.keyboardDistanceFromTextField = 8; //This will modify default distance between textField and keyboard. For exact value, please manually check how far your textField from the bottom of the page. Mine was 8pt.    

    }

enter image description here

+5
source share
9 answers

You can configure the IQKeyboardManager below the properties.

I assume that you included the IQKeyboardManager in the didFinishLaunch of the application delegate, like this

    IQKeyboardManager.sharedManager().enable = true

shouldShowTextFieldPlaceholder to false==> If you want to hide the section of the notes panel

shouldHidePreviousNext to false == > ..

didFinishLaunch AppDelegate,

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    IQKeyboardManager.sharedManager().enable = true

    IQKeyboardManager.sharedManager().enableAutoToolbar = false
    IQKeyboardManager.sharedManager().shouldShowTextFieldPlaceholder = false
    IQKeyboardManager.sharedManager().shouldHidePreviousNext = false


    return true
}
+26

didFinishLaunchingWithOptions AppDelegate:

IQKeyboardManager.sharedManager().enable = true

IQKeyboardManager.sharedManager.enableAutoToolbar = false

.

+8

Swift 3 shouldResignOnTouchOutside, textField, UITextField/UITextView.

ViewController, , ViewController AppDelegate.

:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
  IQKeyboardManager.sharedManager().enable = true
  IQKeyboardManager.sharedManager().enableAutoToolbar = false
  IQKeyboardManager.sharedManager().shouldShowToolbarPlaceholder = false
  IQKeyboardManager.sharedManager().shouldResignOnTouchOutside = true
}
+5

Swift 4.0

IQKeyboardManager.shared.previousNextDisplayMode = .alwaysHide

Swift 4.0

IQKeyboardManager.shared.enableAutoToolbar = false
+3

, :

  • import IQKeyboardManagerSwift View Controller.
  • :

    // MARK: - Helper
    extension <#yourViewController#> {
    
      private func keyboardManagerVisible(_ state: Bool) {
        IQKeyboardManager.shared.enableAutoToolbar = state
      }
    }
    
  • :

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    
        self.keyboardManagerVisible(false)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
    
        self.keyboardManagerVisible(true)
    }
    
+1

IQKeyboardManager Swift 4

, :

func application(_ application: UIApplication, 
     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    //Your other code here       

    // -- enable IQKeyboardManager --
    IQKeyboardManager.shared.enable = false

    return true
}
0

Swift 5.1, Xcode 11

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

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

    return true
}
0

Swift 5, IQKeyboardManager (6.3.0)

didFinishLaunchingWithOptions :

private func setupKeyboardManager() {
    IQKeyboardManager.shared().isEnabled = true
    IQKeyboardManager.shared().isEnableAutoToolbar = false
    IQKeyboardManager.shared().shouldShowToolbarPlaceholder = false
    IQKeyboardManager.shared().previousNextDisplayMode = .alwaysHide
}

, , shouldResignOnTouchOutside .

0

Swift4.2

 //Add these line into didFinishLaunch
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.shouldResignOnTouchOutside = true        
IQKeyboardManager.shared.enableAutoToolbar = false
0

Source: https://habr.com/ru/post/1658169/


All Articles