UIKeyboardWillShowNotification called twice if screen rotates

I create notifications when the keyboard appears and disappears.

override func viewDidLoad(){

super.viewDidLoad()

     // Creates notification when keyboard appears and disappears

     NSNotificationCenter.defaultCenter().addObserver(self, selector:Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification,object:nil)

     NSNotificationCenter.defaultCenter().addObserver(self, selector:Selector("keyboardWillHide:"), name:UIKeyboardWillHideNotification,object:nil)

}

override func viewWillDisappear(animated:Bool){

     NSNotificationCenter.defaultCenter().removeObserver(self, name:UIKeyboardWillShowNotification,object:nil)

     NSNotificationCenter.defaultCenter().removeObserver(self, name:UIKeyboardWillHideNotification,object:nil)

}

func keyboardWillShow(notification:NSNotification){

     self.adjustingHeight(true, notification: notification)

}

func keyboardWillHide(notification:NSNotification){

     self.adjustingHeight(false, notification: notification)

}

The strange behaviour occur when the keyboard is already shown and I rotate the screen. Then the next actions occurs:

  1. UIKeyboardWillHideNotification called
  2. UIKeyboardWillShowNotification called (with the old height of the keyboard)
  3. UIKeyboardWillShowNotification called (with the new height of the keyboard)

The result of this is that my view is not updated properly.

iOS 9.2.1

Posted on Feb 2, 2016 2:56 AM

Reply
1 reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

UIKeyboardWillShowNotification called twice if screen rotates

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.