This seems like it should be easier that it currently is being.
I am trying to center a UIView with an aspect ratio of 1:1 (A square) in any iOS device it is drawn in, regardless of orientation.
For detail: My view has a draw that updates on a timeInterval. I was using a full screen view and computing my square on each draw. On orientation change the whole view went to hell. I assumed that if the view was square, I could trust the orientation change animation.
My constraints have been failing repeatedly, which is why this seems like it should be easier:
View (Square)
Constraints
aspect 1:1
Constraints
View.centerX = centerX
View.centerY = centerY
View.leading ≥ leadingMargin + 5 @ 800
View.top ≥ Top Layout Guide.bottom + 5 @ 800
trailingMargin ≥ View.trailing + 5 @ 800
Bottom Layout Guide.top ≥ View.bottom + 5 @ 800
I have the Content Hugging Prioity at 250
I have the content Compression Resistance at 750
This leaves the constraint errors:
- Missing Constraint: Need constrains for: X position or width
- Missing Constraint: Need constrains for: Y position or height
My confusion is that I can't lock into one dimension because on rotation I need to lock into the other.
As mentioned... this seems like it should be easier.
Center a Square UIView with a border of 5 at the thinner dimension.
(5 to the sides in portrait, 5 to the top and bottom in landscape)
Suggestions warmly appreciated, Explanations would be beyond helpful.