7

I am running the same code on an IOS 7 and IOS 8 device with differing results

Given a screen with two text fields

In IOS 7 if I touch the first field keyboardWillShow is called but if I touch the second field when the keyboard is already shown it is not called a second times.

In IOS 8 keyboardWillShow is called twice

Is this documented behaviour ?

Ryan Heitner
  • 13,119
  • 6
  • 77
  • 119
  • Is one of those a password field? Then maybe this [thread](https://devforums.apple.com/message/1029338#1029338) helps. – dasdom Sep 14 '14 at 10:46
  • @dasdom quite correct I turned off correction and spellcheck in Interface Builder and it was not called twice. Answer the question and I will mark it as correct. – Ryan Heitner Sep 14 '14 at 11:23

2 Answers2

6

The reason is the difference in the keyboard. If the second field is a password field this means there is another keyboard under the hood. Therefore the notification is sent twice.

dasdom
  • 13,975
  • 2
  • 47
  • 58
  • 1
    It doesn't have to be a change in passworded field. Mine transited from a UITextField to a UITextView, and the only different was that the former has it's Correction setting set to "No", and the latter had it to "Default". I switched the "No" to "Default", and it's fine now. – CyberMew Oct 08 '14 at 11:30
0

best is to listen for keyboardWillChangeFrameNotification

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrameNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179
  • 2
    I've just tried that on iOS 9.1 Beta and the `UIKeyboardWillChangeFrameNotification` observer is triggered every time one selects a new UITextField whether the keyboard is already displayed or not. Note that I have 3 text fields and they all use different types of keyboard (username, email, password). Maybe if the text fields all use the exact same keyboard then the observer is only triggered once... – Litome Sep 25 '15 at 21:49
  • i noticed that too, you need to get the end and start frame and compare if they are equal, if yes, you potentially dont need to do anything – Peter Lapisu Sep 26 '15 at 11:39
  • @Litome I'm having the same issue here. Did you manage to fix that issue? – Siddharthan Asokan Oct 09 '15 at 08:29
  • @SiddharthanAsokan I didn't find a fix. I think Peter Lapisu has the truth of it: since iOS 9.1 you need to capture start and end frame (of the keyboard?), compare and only act if they're different. In my case, moving the text fields out of the keyboard's way was cometic, not functional and we had to issue a quick fix as it caused functional issues in the next view. So I just removed the functionality to move the text input fields up altogether. – Litome Oct 12 '15 at 08:45