0

I've registered for keyboard notifications using this code:

_keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardNotification);

OnKeyboardNotification never fires.

So I changed it so that I am now able to see all the notifications using this code:

_keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(null, OnKeyboardNotification);

I printed out to the output window the name of each of the notifications received. The only keyboard related notifications I see when bringing up the keyboard are:

UIKeyboardCandidateCorrectionDidChangeNotification

UIKeyboardLayoutDidChangedNotification

UIKeyboardWillChangeFrameNotification

UIKeyboardPrivateWillChangeFrameNotification

UIKeyboardDidChangeFrameNotification

UIKeyboardPrivateDidChangeFrameNotification

What am I doing wrong? Here is a complete code snippet:

RegisterForKeyboardNotifications()
{
_keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardNotification)

_keyboardHideObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardNotification)

}


private void OnKeyboardNotification(NSNotification notification)
{
   Debug.WriteLine(notification.name);
}
jharr100
  • 1,449
  • 24
  • 51
  • 1
    It seems like AutoLayout changed semantics in iOS 8 for this notification. See this thread: http://stackoverflow.com/questions/26279753/is-there-a-change-to-the-behaviour-of-uikeyboardwillshownotification-in-ios-8 – miguel.de.icaza Feb 28 '15 at 02:55
  • I created a work around where based on the `UIKeyboardDidChangeFrameNotification` I would keep a flag to decide whether the keyboard had been dismissed or not and its working out well. But glad to know there was a change. – jharr100 Mar 10 '15 at 19:55
  • possible duplicate of [iOS8: What's going on with moving views during keyboard transitions?](http://stackoverflow.com/questions/26112319/ios8-whats-going-on-with-moving-views-during-keyboard-transitions) – jharr100 Mar 10 '15 at 19:56

1 Answers1

-2
func RegisterForKeyboardNotifications() {
    let center = NSNotificationCenter.defaultCenter()
    center.addObserver(self, selector: "OnKeyboardNotification:", name: UIKeyboardWillShowNotification, object: nil)
    center.addObserver(self, selector: "OnKeyboardNotification:", name: UIKeyboardWillHideNotification, object: nil)
}




func OnKeyboardNotification(aNotification : NSNotification) {
    println("\(aNotification.name)")
}
mikomi
  • 5
  • 5