-1

I'm familiar with how to get the actual keyboard height via notifications when the keyboard appears, disappears or changes. However I want to have a chat view at the bottom of the screen and some buttons above it. These buttons should be as low as possible (for usability reasons) but should never have to move to not be covered by the keyboard and the chat text field.

In other words, there should be an invisible line at the height where the tallest keyboard's height + the text input's height would come, and the buttons should be aligned with their bottoms to that line.

The challenge is that people use different keyboards having different heights depending on language, device, iOS version and settings. I could add some magic constants and hope things don't change too much between iOS versions but I would rather poll the OS in some kind of way to give me that information instead, so everything just updates automatically between iPhone X, iPhone SE, iPads landscape portrait etcetera.

How can I reserve just enough space for the keyboard before it's actually shown?

Lucas van Dongen
  • 9,328
  • 7
  • 39
  • 60
  • You say you know how to get keyboard height therefore where is the challenge in users having different keyboard heights? Why do you need a magic constant if you know the height? If you don't want the buttons to move with the keyboard, simply move them to the top of the screen. That's a design problem, not a programming problem. – Sulthan May 01 '18 at 15:36
  • Is this what you're asking for? https://stackoverflow.com/a/35689635/5496433 – BallpointBen May 01 '18 at 16:36
  • @BallpointBen the buttons are always visible, not only when you're using the text input. The challenge is having them as close as possible to your thumb while not moving them for the keyboard or having them covered by the keyboard – Lucas van Dongen May 01 '18 at 16:46

1 Answers1

1

Basically, you can't do what you're describing. You never know the height of the keyboard that will appear until it appears. And the user can change the keyboard height after it appears. There no such thing as having your buttons be "as low as possible (for usability reasons) but should never have to move to not be covered by the keyboard and the chat text field." They do have to move.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • The only thing I could think of is using a center Y axis line but that would waste quite some space on taller iPhone X type screens and buttons would be quite hard to reach for one-handed use. – Lucas van Dongen May 01 '18 at 16:15
  • I'm not sure what you're talking about. Scrolling your view upwards, or changing the size of a scroll view's content inset, to compensate for the keyboard when it appears, is totally standard. Just do it. – matt May 01 '18 at 16:19
  • It's slightly jarring and having moving buttons in this case could potentially lead to users pressing the wrong button unintentionally. We noticed this by watching real users use the application. – Lucas van Dongen May 01 '18 at 16:23
  • 1
    But at this point it's a matter of opinion as to what the best _design_ is. That is not what you asked. You asked whether you can know in advance what the highest keyboard will be that the user might ever summon, and the answer is no. – matt May 01 '18 at 18:50