Search code examples
iosswiftuiviewtarget

Bug with keyboard extension constraints on ipad


Overview:
I'm building a keyboard extension and I want it to work both on iPhone and iPad. However, when I run it on iPad it is smaller in width: it's like it cuts off a piece of the view There's no way to adjust it... Here's a picture: enter image description here

What I'm doing:
First of all I added to my project the keyboard target. Then I created in it a xib file. His file owner is the KeyboardViewController. Inside of this xib view I put another view and I constrained it to containing view (not safe area, I tried it as well but it didn't work). Since it didn't work, I tried setting the constraints programmatically but it still didn't work. Furthermore, to set my keyboard's height I put the following code inside of my viewDidLoad:

     let heightConstraint = NSLayoutConstraint(item: self.view!, attribute: NSLayoutConstraint.Attribute.height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 0.0, constant: 280)
                self.view.addConstraint(heightConstraint)

Question:
I don't know anymore what I'm missing, I downloaded some projects from GitHub and they worked fine. What am I doing wrong? How do I adjust the size of my keyboard view to make it equal to the size of the ipad keyboard?


Solution

  • Turns out this is just a simulator's bug. Everything works great on real iPad Air and on other iPad simulators.