How to hide Toolbar in IQKeyboardManager iOS Swift 3

后端 未结 10 2091
南笙
南笙 2021-01-12 09:35

I\'m using the IQKeyboardManger library to scroll text fields when started typing using the keyboard, but I don\'t want to display the default toolbar from their library. Be

相关标签:
10条回答
  • 2021-01-12 09:41

    Swift4.2

     //Add these line into didFinishLaunch
    IQKeyboardManager.shared.enable = true
    IQKeyboardManager.shared.shouldResignOnTouchOutside = true        
    IQKeyboardManager.shared.enableAutoToolbar = false
    
    0 讨论(0)
  • 2021-01-12 09:44

    If you want to hide for a specific controller, you can do like this :

    • import IQKeyboardManagerSwift in your the desired View Controller.
    • Add this extension :

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

      override func viewDidAppear(_ animated: Bool) {
          super.viewDidAppear(animated)
      
          self.keyboardManagerVisible(false)
      }
      
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
      
          self.keyboardManagerVisible(true)
      }
      
    0 讨论(0)
  • 2021-01-12 09:48

    Swift 3 You must use shouldResignOnTouchOutside to resign textField if touched outside of UITextField/UITextView.

    Add this in your ViewController if you want it in an specific ViewController or to override all your application in the file AppDelegate.

    Inside the method:

    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
    }
    
    0 讨论(0)
  • 2021-01-12 09:48

    Swift 4.0 and above For hide previous Next

    IQKeyboardManager.shared.previousNextDisplayMode = .alwaysHide
    

    Swift 4.0 and above For toolbar

    IQKeyboardManager.shared.enableAutoToolbar = false
    
    0 讨论(0)
  • 2021-01-12 09:49

    Enable IQKeyboardManager in Swift 4

    Maybe try this:

    func application(_ application: UIApplication, 
         didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    
        //Your other code here       
    
        // -- enable IQKeyboardManager --
        IQKeyboardManager.shared.enable = false
        
        return true
    }
    
    0 讨论(0)
  • 2021-01-12 09:55

    You can set IQKeyboardManager below properties.

    I assume you have enabled the IQKeyboardManager in didFinishLaunch of app delegate like this

        IQKeyboardManager.sharedManager().enable = true
    

    shouldShowTextFieldPlaceholder to false ==> If you want to hide placeholder toolbar section

    shouldHidePreviousNext to false ==> If you want to hide next and prev button and so on.

    You can enable the settings in didFinishLaunch of AppDelegate like this

    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
    }
    
    0 讨论(0)
提交回复
热议问题