Disable IQKeyboardManager in ViewController in Swift

Viewed 5395

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?

1 Answers

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)
Related