I have a problem with AutoLayout which is causing me a real headache. I have a scrollview & container view set up in a .xib using Autolayout. I need to dynamically add subviews to the container view and am trying to get them to play nice with Auto Layout. This is not going well...
Here is a picture of what I am trying to accomplish:
So the Scroll View and Container Layer are set up in a xib already with autolayout and view 1-3 I am trying to add programatically. My first approach was:
[containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[viewOne]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(viewOne)]]
which resulted in:
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:0x9d84de0 H:|-(20)-[UIView:0x9d922e0] (Names: '|':UIView:0x9d91fb0 )>", "<NSAutoresizingMaskLayoutConstraint:0x9d9fe90 h=--& v=--& UIView:0x9d922e0.midX ==>" )
I have also tried using constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant
but am struggling to get it to work the way I want. Am I doing something fundamentally wrong?
Stephen
[UIView alloc] init]
. I have also tried[UIView alloc] initWithFrame:CGRectNull]
– Stephen GroomtranslatesAutoResizingMaskIntoConstraints
but will try now, ty – Stephen Groom