0

I created a custom keyboard with a xib-file. It works perfectly und shows as I want to, but I get lots of warnings when debugging the keyboard.. I created all the constraints in the xib and add it as a subview to my view.

var nib = UINib(nibName: "Keyboard", bundle: nil)
let objects = nib.instantiateWithOwner(self, options: nil)
mainView = objects.first as UIView
view.addSubview(mainView)

I do this in the viewDidLoad()-method. In the viewDidAppear() I call this to get my height:

let heightConstraint = NSLayoutConstraint(item: self.view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 0.0, constant: 180.0)
        view.addConstraint(heightConstraint)

mainView.frame = view.bounds

But now I get this warnings:

2014-09-17 12:21:21.689 Hodor[6629:1086407] 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:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>",
    "<NSLayoutConstraint:0x1780882f0 V:[UIInputView:0x15e607830(180)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>

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.
2014-09-17 12:21:21.693 Hodor[6629:1086407] 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:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>",
    "<NSLayoutConstraint:0x1780882f0 V:[UIInputView:0x15e607830(180)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>

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.
2014-09-17 12:21:21.697 Hodor[6629:1086407] 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:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>",
    "<NSLayoutConstraint:0x1780882f0 V:[UIInputView:0x15e607830(180)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x178087e40 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x15e607830(264)]>

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.

What does this mean? From the text of the warnings it seems to be something with the height constraint...

Ben
  • 3,455
  • 3
  • 26
  • 31
  • Can you post a screenshot of your constraints and layout from the XIB? It looks like one constraint has given the keyboard an explicit height of 180 points. But, then a separate constraint (either from distance to top + distance to bottom, etc.) of what seems to be the containing superview is trying to set it to 264. Someone with more experience parsing those errors may be able to narrow it down. – Craig Otis Sep 17 '14 at 10:35
  • So, here is the Layout: https://cloudup.com/crqoINgTXqg The constraints I have made: - the next button is in the lower left corner and size is fixed to 60x60 - the left button is in the right upper corner, has a fixed width of 60 and the same height as the down button - the down button is in the right bottom corner, has also a fixed width of 60 and has the same height as the left button - the big button in the middle if fixed to the left, right, upper and button frame with distance of 0 The view itself is 320x180 in the xib and the keyboard should be 180 in height... – Ben Sep 17 '14 at 10:47
  • Please look at the [accepted answer][1] from @skyline75489. It works! [1]: http://stackoverflow.com/questions/24167909/ios-8-custom-keyboard-changing-the-height/25819565#comment40988935_25819565 – lifjoy Oct 02 '14 at 00:27

2 Answers2

2

Try this

view.setTranslatesAutoresizingMaskIntoConstraints(false) view.addConstraint(NSLayoutConstraint( item:mainView, attribute:.Left, relatedBy:.Equal, toItem:view, attribute:NSLayoutAttribute.Left,multiplier:0.6, constant: 0))

    view.addConstraint(NSLayoutConstraint(
        item:mainView, attribute:.Right,
        relatedBy:.Equal, toItem:view,
        attribute:.RightMargin,multiplier:0.6, constant: 0))

    view.addConstraint(NSLayoutConstraint(
        item:mainView, attribute:.Width,
        relatedBy:.Equal, toItem:view,
        attribute: .Width,multiplier:0.6, constant: 0))

    view.addConstraint(NSLayoutConstraint(
        item:mainView, attribute:.Height,
        relatedBy:.Equal, toItem:view,
        attribute:.Height,multiplier:0.6, constant: 0))
Ben
  • 3,455
  • 3
  • 26
  • 31
Ramesh
  • 617
  • 6
  • 16
  • If I do this, the view from the nib is much too small or too big, whether I set it before or after the meinView.frame = view.bounds. And there is also a warning left. Not that many as before but it is one warning that says the same as above. – Ben Sep 17 '14 at 11:02
  • @BenjaminHerzog for mainView add same constrains and remove mainView.frame = view.bounds – Ramesh Sep 17 '14 at 11:08
  • I wrote this right after the heightconstraint in the viewDidAppear(). The mainView which is my nib with own constraints via interface builder is way too big. I wrote: mainView.frame = view.frame view.setTranslatesAutoresizingMaskIntoConstraints(false) mainView.setTranslatesAutoresizingMaskIntoConstraints(false) – Ben Sep 17 '14 at 11:10
  • @BenjaminHerzog after that what is result now – Ramesh Sep 17 '14 at 11:14
  • @BenjaminHerzog write all the code in viewDidAppear() – Ramesh Sep 17 '14 at 11:15
  • The result is that the mainView from the nib is way too big. I can only see the upper left corner because the rest is too big to be on screen. – Ben Sep 17 '14 at 11:15
  • @BenjaminHerzog in constrain set toItem: self.veiw – Ramesh Sep 17 '14 at 11:17
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/61411/discussion-between-benjamin-herzog-and-ramesh). – Ben Sep 17 '14 at 11:18
0

There are some conflicts with constraints. Autoresize is conflicting with constraints you have applied.

Saqib Omer
  • 5,387
  • 7
  • 50
  • 71
  • But which constraints? In the text are no names of my outlets.. I wrote my constraints in the comment under the question, could you take a look please? :) – Ben Sep 17 '14 at 10:48
  • Whenever you add constraint for height you must set constraints on its vertical (x) and horizontal (y) position. Setting these constraints will resolve this conflict with autoresize. – Saqib Omer Sep 17 '14 at 11:13
  • I have set the horizontal and vertical position via the upper right corner constraints. So the control left button for example is in the upper right corner.. always.. And then I set the size of it. What I don't understand.. The keyboard looks fine, like it should. Why are the warnings there? – Ben Sep 17 '14 at 11:17