Changing the custom keyboard height is just as per the documentation . Here is a quick equivalent version of the code shown in the Apple documentation
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) let constraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 400.0) self.view.addConstraint(constraint) }
This works, but it changes the height to a CONSTANT value, which is undesirable if you change the orientation of the device. Setting the keyboard height to 400.0 can be fine in portrait mode, but most likely it will not be suitable in landscape mode. For example: The standard keyboard size for iPhone 5 is 320,216 in portrait and 568,162 in landscape. Setting a constant height changes the size of the keyboard view to 320,400 in the portrait and 568,400 (which is actually the entire screen) in the landscape.
My only thought now is to create a dictionary containing the size of the keyboard representation for each type of device and each orientation, and then update the constant height constraint every time the device changes orientation. Has anyone found a more elegant solution?
source share