title: iOS center a view
body: <p>I have an class which adds a UIActivityIndicator to a specified view. I want to center the UIActivityIndicator in the given view. </p>
  
  <p>I thought this work correctly since the UIActivityIndicator wasn't on screen very long. Now I see that when I rotate the screen when he is active, the UIActivityIndicator isn't centered anymore.</p>
  
  <p>The way I did it was: </p>
  
  <pre><code>CGRect frame = CGRectMake((view.frame.size.width / 2 - self.activityIndicator.frame.size.width / 2),
                            (view.frame.size.height / 2 - self.activityIndicator.frame.size.height / 2),
                            self.activityIndicator.frame.size.width,
                            self.activityIndicator.frame.size.height
                           );
  </code></pre>
  
  <p>Which gives a better result then:</p>
  
  <pre><code>self.activityIndicator.center = view.center;
  </code></pre>
  
  <p>Is there some way I can add a constraint so it stays in the middle even when rotated. I know this can be done in IB, but in code I have no idea?</p>