I ran the following code in iOS8 using both Apple's Default Keyboards and 3rd Party Keyboards:
class ViewController: UIViewController {
var checkValue: CGRect?
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateViews:", name: UIKeyboardWillShowNotification, object: nil)
}
func updateViews(notification: NSNotification){
if let userInfo = notification.userInfo {
let endKeyboardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey]!).CGRectValue()
checkValue = endKeyboardFrame
}
println(checkValue)
}
}
For example, this is the output for SwiftKeys:
(0.0, 667.0, 375.0, 0.0)
(0.0, 451.0, 375.0, 216.0)
(0.0, 409.0, 375.0, 258.0)
whereas Apple's Default Keyboard:
Optional((0.0, 409.0, 375.0, 258.0))
It seems for Apple's default keyboards, the code gets called once as expected [e.g. tapping on a textfield]. However for 3rd party keyboards, it gets called multiple times. Why is this? I do not want to disable 3rd party keyboards.
In my main project, I am updating views, which is causing code to run multiple times.