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:
- UIKeyboardWillHideNotification called
- UIKeyboardWillShowNotification called (with the old height of the keyboard)
- 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