Amrit Sidhu
Amrit Sidhu

Reputation: 1950

IQKeyboardManager issue when using navigation bar

I am using IQKeyboardManager for my iOS app.

When I first launch the app, I tap on a button which unhides a view that contains a text field. On tapping the text field, the IQKeyboardManager shifts the whole view upwards so that the text field is not hidden by the keyboard. But when I navigate to some other view and come back to the previous view and I click the button to unhide a view containing the text field, the IQKeyboardManager does not shift the view upwards.

I cannot understand the cause. Any suggestions will be appreciated.

Upvotes: 3

Views: 5149

Answers (2)

Lumialxk
Lumialxk

Reputation: 6369

This is better.It won't effect other VC:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [IQKeyboardManager sharedManager].enable = NO;
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [IQKeyboardManager sharedManager].enable = YES;
    [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
}

In Swift

override func viewWillAppear(_ animated: Bool) {
   IQKeyboardManager.shared.enableAutoToolbar = false
   IQKeyboardManager.shared.enable = false
}
    
override func viewWillDisappear(_ animated: Bool) {
   IQKeyboardManager.shared.enableAutoToolbar = true
   IQKeyboardManager.shared.enable = true
}

Upvotes: 4

Maged Mohammed
Maged Mohammed

Reputation: 11

With Swift 5

import IQKeyboardManager

// add This in viewDidLoad
IQKeyboardManager.shared().disabledDistanceHandlingClasses.add(LoginViewController.self)

Upvotes: 0

Related Questions