I am working on a custom iOS keyboard. I would like to partition the keyboard view into two views on the top and bottom and a scroll view in the middle. I have the topView and bottomView set up, but when I attempt to add the middle scrollView, there are layout issues. Here is a picture of the layout I am trying to create. The green is the topView, the blue is the scrollView, and the red is the bottomView.
To set the middle scrollView, I set the left and right constraints to the left and right edge of the containing view. The top and bottom edges are set to the bottom of the topView and top of the bottomView respectively. Here is my code for drawing the middle scroll wheel:
self.tileScrollView = UIScrollView()
self.tileScrollView.sizeToFit()
self.tileScrollView.setTranslatesAutoresizingMaskIntoConstraints(false)
self.tileScrollView.backgroundColor=UIColor.blueColor()
var leftSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0)
var rightSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1.0, constant: 0.0)
var topSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Top, relatedBy: .Equal, toItem: self.topView, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
var bottomSideConstraint = NSLayoutConstraint(item: self.tileScrollView, attribute: .Bottom, relatedBy: .Equal, toItem: self.bottomView, attribute: .Top, multiplier: 1.0, constant: 0.0)
self.view.addSubview(self.tileScrollView)
self.view.addConstraints([leftSideConstraint, rightSideConstraint, topSideConstraint, bottomSideConstraint])
It is worth noting that when the constraint is broken, the keyboard renders correctly. Here is the error output:
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:0x60800008f5f0 UIView:0x7f8c33f03740.bottom == UIInputView:0x7f8c33c09c20.top + 30>",
"<NSLayoutConstraint:0x60800008f7d0 V:[UIInputView:0x7f8c33c09c20]-(-30)-[UIView:0x7f8c33f03cb0]>",
"<NSLayoutConstraint:0x60800008fb40 V:[UIView:0x7f8c33f03740]-(0)-[UIScrollView:0x7f8c33f03dc0]>",
"<NSLayoutConstraint:0x60800008fb90 UIScrollView:0x7f8c33f03dc0.bottom == UIView:0x7f8c33f03cb0.top>",
"<NSLayoutConstraint:0x60000008e7e0 'UIView-Encapsulated-Layout-Height' V:[UIInputView:0x7f8c33c09c20(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x60800008fb40 V:[UIView:0x7f8c33f03740]-(0)-[UIScrollView:0x7f8c33f03dc0]>
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.
Does anyone have any insight on this error?
Thanks