Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling with IQKeyboardManager.sharedManager().enable doesn't work #829

Closed
pilot34 opened this issue Apr 21, 2017 · 9 comments
Closed

Comments

@pilot34
Copy link

pilot34 commented Apr 21, 2017

I use IQKeyboardManager only on one ViewController, I do
IQKeyboardManager.sharedManager().enable = true in viewWillAppear and
IQKeyboardManager.sharedManager().enable = false in viewWillDisappear.

But on another screen IQKeyboardManager handles textFieldDidBeginEditing notifications and I have bugs related to #88

Should it work so or is it a bug? In my opinion when you disabling IQKeyboardManager it should unsubscribe from all notifications and shouldn't work at all until it will be enabled later.

I attached small example project, when I enabling and disabling IQKeyboardManager, but it shows toolbar and handles notifications after disabling.

TestIQKeyboardManager.zip

@pilot34 pilot34 changed the title Disabling IQKeyboardManager doesn't work Disabling with IQKeyboardManager.sharedManager().enable doesn't work Apr 21, 2017
@alfonzm
Copy link

alfonzm commented Apr 21, 2017

Have you tried using the enabledDistanceHandlingClasses property? Check out the documentation: https://github.com/hackiftekhar/IQKeyboardManager/blob/master/MANUAL%20MANAGEMENT.md#enabledisable-distance-handling-between-different-viewcontrollers

@pilot34
Copy link
Author

pilot34 commented Apr 21, 2017

@alfonzm enabledDistanceHandlingClasses won't disable anything better than enable = false property:

I want to say that if I turn off the library with enable = false, I expect that it will not intercept any of my app's notifications and change app's behaviour. But in current API when enabledDistanceHandlingClasses has higher priority then enable it can't be done..

Maybe it will be fixed when IQKeyboardManager won't call canBecomeActive in the next version..

@kmcgill88
Copy link

@pilot34 I'm in the same position as you. Have you found a work around?

@kmcgill88
Copy link

@pilot34 - @alfonzm I forked and made a couple of changes that is working great for my needs. Instead of a canBecomeActive I went ahead and just destroyed the singleton altogether.

In my case I'm using KMKeys,a library of mine which subscribes to the same events. The text field is not part of a view controller there so, disabledDistanceHandlingClasses won't work for me.

A quick solution is to just destroy it when I'm done and re-create before use.

    override func viewWillAppear(_ animated: Bool) {
        IQKeyboardManager.sharedManager().enable = true
        IQKeyboardManager.sharedManager().enableDebugging = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        IQKeyboardManager.destroy()
    }

Another idea would be simply hiding if visible then removing the observer. NotificationCenter.default.removeObserver(self) then adding the observers later again when needed.

Either way I think something like this could be introduced without affecting the current API.

@pilot34
Copy link
Author

pilot34 commented Apr 27, 2017

I forked and made a couple of changes that is working great for my needs.

good solution 👍

@pilot34 I'm in the same position as you. Have you found a work around?

I removed IQKeyboardManager and implemented all keyboard staff manually... In my case it was easier then forking the lib.

@hackiftekhar
Copy link
Owner

First thing is that there is a separate property to enable/disable keyboard toolbar. The second thing is that there was a workaround for handling the issue with textFieldDidBeginEditing, with master branch now I've fixed this issue. Third one is that I now added unregisterAllNotifications method to completely unregister for all notification at developer risk.

@pilot34
Copy link
Author

pilot34 commented May 7, 2017

Third one is that I now added unregisterAllNotifications method to completely unregister for all notification at developer risk.

👍

@hackiftekhar
Copy link
Owner

That's the best line for developers I think @pilot34. ha ha ha.

@shahdhiren
Copy link

Is destroy method removed? I want to enable keyboard manager only in 2 of the screen. Is that possible?

IQKeyboardManager.destroy()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants