Tarek
Tarek

Reputation: 823

Custom Keyboard Height via Storyboard

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

Upvotes: 1

Views: 629

Answers (1)

DarkAgeOutlaw
DarkAgeOutlaw

Reputation: 587

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)

Upvotes: 1

Related Questions