5

To disable IQKeyboardManager in a viewcontroller in Swift, you apparently need to get a reference to the instance and then disable it. However, I cannot figure out a way to reference it. I originally import the library in the appDelegate which is written in Objective-C as

import IQKeyboardManagerSwift

Give me the error:

No Such Module IQKeyboardManagerSwift

If I merely try to put the lines below in viewDid Load:

IQKeyboardManager.shared().isEnabled = false
IQKeyboardManager.shared().isEnableAutoToolbar = false

Then I get error

IQKeyboardManager not found.

How do you disable IQKeyboardManager for a specific view controller in Swift?

zztop
  • 701
  • 1
  • 7
  • 20

1 Answers1

7

The documentation mentions a possible solution: (the syntax may be a bit different depending on the version of the framework you're using)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        IQKeyboardManager.shared().isEnabled = true
        IQKeyboardManager.shared().enabledDistanceHandlingClasses.append(EnabledViewController.self)
        IQKeyboardManager.shared().disabledDistanceHandlingClasses.append(DisabledViewController.self)
        return true
    }

if you need the toolbar disabled/enabled as well

IQKeyboardManager.shared().enabledToolbarClasses.append(ToolbarEnabledViewController.self)
IQKeyboardManager.shared().disabledToolbarClasses.append(ToolbarDisabledViewController.self)
Slavenko Miljic
  • 3,836
  • 2
  • 23
  • 36