I have an observer for UIKeyboardWillShowNotification and UIKeyboardWillHideNotification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
It all works, except it works when the viewController is not currently visible.
I've tried comparing to self.navigationcontroller.topViewController but this doesn't work when I have a modal view presented as the topViewController is the one underneath the modal view controller.
If you're using UIViewController you could register your instance for Keyboard Notifications when the view becomes visible inside viewWillAppear: and then de-register when the view gets hidden inside viewWillDisappear:
This way you won't receive notifications when the view is not visible.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With