Keyboard Pushing Up Text Fields

I am having an issue with the keyboard pushing up the text field out of view. When I close the keyboard or swipe down, the field comes back into view. It seems to go into affect when I pinned the field using auto layout

That should not happen. Can you double-check that you pinned the Text Field using the right constraints, and that you didn’t – inadvertently – put any constraints on the view controller that shouldn’t be there?

I definitely have checked multiple times and I even compared the constraints on each file compared to the UI Improvements. I went ahead and ran your code from the UI Improvements, and it has the same functionality/bug.

  1. Run app on iPhone SE
  2. Go into a new list
  3. Click + to add new item
  4. If keyboard is not active in sim, click command + k to open keyboard. (If keyboard is active, skip to step 7)
  5. hit cancel
  6. Click add again
  7. Keyboard should open immediately when you go to this scene and push the text out of view

To get Text Field back,

  1. command + k to hide keyboard, text field should show
  2. command + k to bring back keyboard and everything should stay the same.

This is the most drastic on the SE in the simulator, but on my 6plus, it happens slightly on the add list page (presumably since there is more content on it?) so it seems that it is not just an xcode bug.

These screenshots are from the UI Improvements Project that came with the book:

Removing the keyboard:

Adding keyboard back:

Lastly, here is my github link to this project, though as I stated, seems to happen in both mine and the one from the book: https://github.com/kickinbahk/swift-checklists

Ah yes, I have seen this problem. This is definitely a bug in Xcode or the simulator. (After all, the app isn’t really doing anything special: it’s just a text field in a table view. And it has worked without problems since iOS 5.)

During the iOS 10 beta, Apple admitted there were problems with modally presented screens (like this is) and I suspect not all of these problems have been solved.

However, I haven’t seen it happen on an actual device, only on the simulator. Are you saying it happens on your 6 Plus device too?

(To get the text field back, you can also “pull down” on the screen, just like when you’d be scrolling it.)

Issue on the Edit Item page:

OK, I guess it’s not a simulator bug then. :frowning: It’s definitely something that didn’t happen before iOS 10. Let’s hope it is fixed in 10.1.

Ah, well appreciate you taking the time to take a look :smile:

I’ve come across the same problem just then (both on a physical device and the simulator). Oddly enough, I found that if either no constraints are set on the text field, or they’re only partially set (so a warning comes up), the keyboard doesn’t push up the text field. If all the constraints are set on the text field, then the issue appears.

This definitely hasn’t occurred in the iOS 9 (the 4.1 tutorials), as I’ve gone through those and everything worked perfectly. Looks like a bug in iOS 10, as mentioned earlier

Until this thread I didn’t realize it was related to the constraints, so it’s good to have that insight. :slight_smile:

This is a strange, but if we comment call to super.viewWillAppear(animated) both in ListDetailViewController and ItemDetailViewController this solve the problem:

override func viewWillAppear(_ animated: Bool) {
    // super.viewWillAppear(animated)
    textField.becomeFirstResponder()
}

Seems this is bug in iOS 10.

2 Likes