My app monitors changes to the keyboard to animate specific parts of the UI using UIKeyboardWillShow
and UIKeyboardWillHide
notifications.
The issue I am having is that when I switch from the Messages app with the keyboard shown to my app using the app switcher (in a state where the keyboard is not required), it will trigger the UIKeyboardWillShow
notification and then the UIKeyboardWillHide
notification which is resulting in my UI jumping up and down a bit.
Is there a way to only listen to keyboard notifications for your own app?
ViewWillAppear
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillChange:", name: UIKeyboardWillChangeFrameNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
ViewWillDisappear
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillChangeFrameNotification, object: nil)