1

So I'm making a custom keyboard however its height is forced for some reason. I tried changing some options in the View's Attributes and Size Inspectors but it never helped.

Here are my attempts so far.
Attempt 1 small
Attempt 1 temporary

As you can see, when I run my project, the keyboard's height becomes too small compared to Apple's iOS keyboard. I noticed that for a brief second, the keyboard's height becomes normal (same size as Apple's iOS keyboard).

I then tried to force the height by giving the keyboard's containing view a fixed height, instead of just pinning it to the top border of the container. It worked but it covered all the screen of coarse so it's totally not practical.

So I tried giving it a proportional height with respect to the container's height, with different multiplier values like 0.3, but it reverted to the original behavior. It also filled the the remaining space that would typically be occupied by the correct Apple's iOS keyboard size, with a white background color.

I'm using a Vertical StackView which contains 3 Horizontal StackViews with all the buttons. I tried removing the StackViews and testing with just a plain view but it also got shrunk the same way so I guess it has something to do with the fact that this is a custom keyboard extension. As for the code, I haven't edited anything in the keyboard's ViewController's template except for an action for the buttons to read their titles and insert text.

In case it wasn't clear, I got to this stage by creating a Single View Application project and I added a Custom Keyboard extension to it, as a new Target. I added a Storyboard and I pointed the Main Interface to it.

Any ideas on how I can achieve a custom height that would be a function of the container's height?

Thanks a lot

Tarek
  • 783
  • 10
  • 31
  • 1
    I don't see why my question got down voted even tho this question was never answered properly on Stack Overflow. – Tarek Mar 18 '17 at 13:16
  • I also facing the same problem and not yet find a solution. I am looking for exactly what gBoard like. Please let me know once you got the solution. my question https://stackoverflow.com/questions/48802380/custom-keyboard-height-is-more-than-default-keybaord – Deepak Sasindran Mar 27 '18 at 06:02

1 Answers1

1

I answered you on Reddit, but that was wrong. I had my keyboard set up differently than you. Have you tried adding a constraint in viewDidLoad()

let constraint = NSLayoutConstraint(item: self.view,
                                           attribute: .height,
                                           relatedBy: .equal,
                                           toItem: nil,
                                           attribute: .notAnAttribute,
                                           multiplier: 0.0,
                                           constant: 500) // Set custom height here
self.view.addConstraint(constraint)
DarkAgeOutlaw
  • 527
  • 4
  • 8
  • I haven't had a chance to try out any suggestions yet bec of my studies but one thing I tried is designing my keyboard in a XIB file. Surprisingly it worked like a charm and it inherited Apple's iOS default keyboard's height regardless of the device size and orientation. I may not need to change the height since the default keyboard's height is good (at least at this stage in my project) but at least it works unlike the issue I have in Storyboard where it would shrink on its own. – Tarek Mar 22 '17 at 15:35
  • Okay this actually WORKED well along with the keyboard's NIB file. So without setting the constraint, the keyboard will inherit the default iOS keyboard height. This just works perfectly. I added the code in the updateViewConstraints() method and the NIB's code in the viewDidLoad(). Works well and automatically adapts to different orientations. I still wonder what exactly is wrong with Storyboards :S I marked your solution as Accepted. Thanks again :) – Tarek Mar 22 '17 at 19:11