title: iOS 9 Autolayout: A centered square
body: <p>This seems like it should be easier that it currently is being.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>My constraints have been failing repeatedly, which is why this seems like it should be easier:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I have the Content Hugging Prioity at 250<br/>
  I have the content Compression Resistance at 750<br/></p>
  
  <p>This leaves the constraint errors:<br/>
   - Missing Constraint: Need constrains for: X position or width<br/>
   - Missing Constraint: Need constrains for: Y position or height</p>
  
  <p>My confusion is that I can't lock into one dimension because on rotation I need to lock into the other.</p>
  
  <p>As mentioned... this seems like it should be easier.
  Center a Square UIView with a border of 5 at the thinner dimension.<br/>
  (5 to the sides in portrait, 5 to the top and bottom in landscape)</p>
  
  <p>Suggestions warmly appreciated, Explanations would be beyond helpful.</p>
  
  <p><a href="https://i.stack.imgur.com/EMhc1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EMhc1.png" alt="enter image description here"></a></p>