Ben
Ben

Reputation: 3485

Swift - Custom Keyboard Height

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...

Upvotes: 0

Views: 2113

Answers (2)

Ramesh
Ramesh

Reputation: 617

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))

Upvotes: 2

Saqib Omer
Saqib Omer

Reputation: 5477

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

Upvotes: 0

Related Questions