Search code examples
iosautoresizingmask

iOS: Using auto resize mask to keep UIView at bottom of phone, no matter the screen size


http://note.io/14639No

I've attached a screenshot of a color view I would like to have positioned at the bottom of the screen using the auto resize mask.

I've tried every combination of resize masks I can think of, but when I change the simulated metric's Size to 3.5 or 4 inch, it doesn't move. :(

What am I doing wrong? Is this possible with auto resizing masks?

enter image description here

Edit Attached an image with me anchoring to bottom as well.


Solution

  • What you probably want is something like:

    enter image description here

    The fixed i-beam (the vertical "strut") at the bottom says "keep my distance to the bottom constant" (i.e. stay pegged at the bottom). The lack of the up-down arrow (the "spring") says "don't change my height as my superview's height changes."

    The other three, horizontal components are optional: the left and right i-beams (struts) say "if I go between landscape and portrait, keep the left and right distances pegged where they are" and the left and right arrow in the middle (the spring) says "and let this change the width as the superview gets wider or narrower."

    This will fix the 3.5" vs 4.0" problem. It should also handle different widths as well (e.g. landscape or if you ever use this scene as subview in custom container or if Apple ever releases larger screen devices), should you ever need that.


    In your revised question, you say that that when you used this autosizing setting, it didn't fix the problem until you rebuilt the scene from scratch, at which point using this autosizing setting did fix it. The likely problem in that original scene was probably, as VinceBurn points out, that in addition to the above autosizing settings, one of the superviews of this bottom view was probably not, itself, autosizing correctly. One always has to consider not only the current view's autosizing settings, but also all of the views in the view hierarchy.