iosobjective-ciphoneswiftiqkeyboardmanager

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.


Solution

  • 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
    }