Reputation: 1343
I'm having major problems with auto layout in iOS 8. I'm working on a custom keyboard, but I can not get the view to display at the correct height. The rendered view on the device comes out too low, more like the intended height of the UIImageView alone. I've set the constraints as shown in the image:
But I keep getting this error in the log, that tells me nothing (probably because I don't understand where to look):
2014-12-06 19:56:45.095 [40268:12181198] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this:(1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x600000096940 V:[UIInputView:0x7fe780d3f600(246)]>",
"<NSLayoutConstraint:0x600000097390 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x7fe780d3f600(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000096940 V:[UIInputView:0x7fe780d3f600(246)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
I've tried following the code in iOS 8 Custom Keyboard: Changing the Height, but it still wont work.
Edit:
I'm setting my height constraint using the following function:
override func updateViewConstraints() {
super.updateViewConstraints()
// Add custom view sizing constraints here
let changeToOrientation = deviceInfoService.getOrientationForView(self.inputView)
if (changeToOrientation == Orientation.Portrait) {
self._heightConstraint!.constant = 246
self.inputView.addConstraint(self._heightConstraint!)
} else {
self._heightConstraint!.constant = 192
self.inputView.addConstraint(self._heightConstraint!)
}
}
Upvotes: 2
Views: 1993
Reputation: 4565
This looks like a bug in the iOS Custom Keyboard implementation. The workaround currently is to adjust your constraint's priority to more/less than 1000
Upvotes: 6
Reputation: 961
This looks similar to how a TodayExtension height can be provided. Try this:
self.preferredContentSize = CGSizeMake(320, 246);
That's how I set the height of my today extension vs setting height constraints explicitly. I'll try this myself, just putting together a sample keyboard project now.
Upvotes: 1
Reputation: 3296
The error tells you that you have conflicting constraints. UIView-Encapsulated-Layout-Height
seems to be a pre-defined height (When searching I mostly found references to its usage in UICollectionView
). My guess is that it's the height defined by the OS that your keyboard is allowed to be. The other constraint is most likely the intrinsic content size of your created view (316 and 30 does indeed add up to 246).
My conclusion is that you probably did something wrong when you changed the height. As I'm not too familiar with keyboard extension development I can't tell you what. However when it comes to the Today Extensions which I have worked a bit with, there was a method you could override which specified the height of the widget.
Upvotes: 2