Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In addition to what @Jasarien and @Brad have said, don't forget that you can force auto-centering using the Autosizing springs and struts. Essentially (in Interface Builder) you click around until there are no Autosizing lines visible, like this:</p> <p><a href="http://gallery.me.com/davedelong/100084/Screen-20shot-202010-03-26-20at-2010-49-18-20AM/web.jpg?ver=12696222220001">alt text http://gallery.me.com/davedelong/100084/Screen-20shot-202010-03-26-20at-2010-49-18-20AM/web.jpg?ver=12696222220001</a></p> <p>In code, you set the <code>-[UIView autoresizingMask]</code> to:</p> <pre><code>(UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin) </code></pre> <p>If you do these, then the view stays centered automatically.</p> <p><strong>EDIT #1</strong></p> <p>Answering your edit, you can't do:</p> <pre><code>self.view.center = self.view.superview.center; </code></pre> <p>Unless your view has been added as a subview of another view (<code>[anotherView addSubview:self.view];</code>). My guess is that <code>self.view.superview</code> is returning <code>nil</code>, and so you're (luckily) getting <code>{0,0}</code> as the return value when trying to invoke <code>center</code> on <code>nil</code>.</p> <p>The proper place to center your view would probably be in the <code>viewWillAppear:</code> method of the view controller. Once the view is about to appear, you know that it <em>must</em> have a superview (otherwise how else would it be about to appear?). You could safely set your view's <code>center</code> there.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload