Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguity with two inequality constraints

Tags:

ios

autolayout

screenshot

I want to have the bottom view be at least 20 away from both the image and the label above it. The label is multiline, so it can be taller or shorter than the image view, depending on how much text there is. When I add two "distance to nearest neighbour >= 20" constraints like shown in the screenshot, Xcode tells me constraints are ambiguous.

How do I fix it?

like image 372
Alex B Avatar asked Nov 20 '13 04:11

Alex B


People also ask

What are inequality constraints?

An inequality constraint g(x, y) ≤ b is called binding (or active) at a point. (x, y) if g(x, y) = b and not binding (or inactive) if g(x, y) < b. Again we consider the same Lagrangian function. L(x, y, λ) = f(x, y) − λ[g(x, y) − b].

What is equality constraints and inequality constraints?

Violated constraint: An inequality constraint gi(x) ≤ 0 is said to be violated at a design point x(k) if it has a positive value there (ie, gi(x(k)) > 0). An equality constraint hi(x(k)) = 0 is violated at a design point x(k) if it has a nonzero value there (ie, hi(x(k)) ≠ 0).

What is an ambiguous layout?

Ambiguous layouts occur when the system of constraints has two or more valid solutions. There are two main causes: The layout needs additional constraints to uniquely specify the position and location of every view.

Has ambiguous layout?

A Boolean value that determines whether the constraints impacting the layout of the view incompletely specify the location of the view.


1 Answers

I think you can do it like this, if I understand your requirements:

enter image description here

The image view has a fixed width and height, and constraints to the left side and top, as well as a constraint to the bottom view of =20 with a priority of 700. That's crucial -- that will set the y position of that bottom view (which has fixed height and constraints to the two sides), but will allow it to move lower if another constraint with higher priority makes it. That constraint with higher priority is the constraint to the label -- it's >=20 with priority of 1000 (the label also has constraints to the top, right side, and trailing edge of the image view).

like image 72
rdelmar Avatar answered Oct 02 '22 18:10

rdelmar