title: How to combine Auto Layout constraints with contentMode property of UIView
body: <p>I have a <code>UIImageView</code> object configured with Auto Layout. I have created constraints so that the view keeps a constant distance to its superview. In visual format it would be like:</p>
  
  <pre><code>@"V:|-[imageView]-|"
  @"H:|-[imageView]-|"
  </code></pre>
  
  <p>But I would also like to keep the aspect ratio of the underlying image, so I have assigned <code>UIViewContentModeScaleAspectFit</code> to <code>contentMode</code>.</p>
  
  <p>I thought everything was working well until I set the <code>cornerRadius</code> value of the associated <code>CALayer</code>:</p>
  
  <pre><code>self.imageView.layer.cornerRadius = 7;
  self.imageView.layer.maskToBounds = YES;
  </code></pre>
  
  <p>Now when the image view is resized, e.g. due to a change in orientation, the rounded corners are lost depending on the new size the view gets. The reason is that <code>cornerRadius</code> applies to the <code>UIImageView</code> (frame in dashes below), but since the underlying image is also resized to respect <code>contentMode</code> (frame in asterisks below), rounded corners are not visible anymore:</p>
  
  <pre><code>--------------------------
  |       **********       |
  |       *        *       |
  |       *        *       |
  |       *        *       |
  |       **********       |
  --------------------------
  </code></pre>
  
  <p>Is there a way to prevent this behavior?</p>