IOS 8 custom keyboard: change height without warning "Can't satisfy constraints at the same time ..."
There are several SO answers on how to change the height of a custom keyboard. Some of them work, for example here , but the ones that work lead to a limitation of the conflict error printed in the console output:
Unable to simultaneously satisfy constraints...
Will attempt to recover by breaking constraint...
Here is my very simple keyboard controller that sets a custom keyboard height (that's Swift):
class KeyboardViewController: UIInputViewController {
private var heightConstraint: NSLayoutConstraint?
private var dummyView: UIView = UIView()
override func updateViewConstraints() {
super.updateViewConstraints()
if self.view.frame.size.width == 0 || self.view.frame.size.height == 0 || heightConstraint == nil {
return
}
inputView.removeConstraint(heightConstraint!)
heightConstraint!.constant = UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ? 180 : 200
inputView.addConstraint(heightConstraint!)
}
override func viewDidLoad() {
super.viewDidLoad()
self.dummyView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.view.addSubview(self.dummyView)
view.addConstraint(NSLayoutConstraint(item: self.dummyView, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0))
view.addConstraint(NSLayoutConstraint(item: self.dummyView, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0))
heightConstraint = NSLayoutConstraint(item: view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 0.0)
}
}
This is causing an annoying output error that my constrain heightConstraint
I added to updateViewConstraints
is in conflict with the constraint denoted as UIView-Encapsulated-Layout-Height
.
I tried to remove the conflicting constant ( UIView-Encapsulated-Layout-Height
) in the updateViewConstraints
following way:
let defaultHeightConst = inputView.constraints().filter() {c in (c as? NSLayoutConstraint)?.identifier == "UIView-Encapsulated-Layout-Height"}.first as? NSLayoutConstraint
if defaultHeightConst != nil {
inputView.removeConstraint(defaultHeightConst!
}
It didn't help, the exit warning is still there. How can I solve this? Specifically, what can I do to get rid of the output error message?
source to share