I came across the same issue and finally resolved it by adding fixed height for the custom keyboard in its viewWillAppear method by adding a height constraint directly to the keyboard view.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let desiredHeight: CGFloat = 250 // Set a default height
// Remove any existing height constraint to avoid conflicts
view.constraints.forEach { constraint in
if constraint.firstAttribute == .height {
view.removeConstraint(constraint)
}
}
let heightConstraint = NSLayoutConstraint(
item: view!,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .notAnAttribute,
multiplier: 1.0,
constant: desiredHeight
)
view.addConstraint(heightConstraint)
}
This code snippet removes any existing height constraint on the keyboard view before adding the new height constraint. It sets a fixed height (desiredHeight) for the keyboard view when it appears. Hope this helps.