Open plivesey opened 8 years ago
Here is some code which I think should produce an ambiguous layout:
NSDictionary *viewsDictionary = @{
@"view1": view1,
@"view2": view2
};
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[view1]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[view2]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[view1]-[view2]-|" options:0 metrics:nil views:viewsDictionary]];
[superview addConstraint:[NSLayoutConstraint constraintWithItem:superview
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:100]];
[superview addConstraint:[NSLayoutConstraint constraintWithItem:superview
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:100]];
For others looking at this ticket, I have managed to reproduce ambiguous layout errors in another project. I haven't updated the unit tests in the library yet, but the check is still valid and useful.
See UnitTestViews.m
For unit testing, the test has yet to come up with a view which actually has ambiguous layout according to the OS. It always seems to return true.
Maybe looking up some examples from WWDC videos would give some good examples.