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

StackOverflow https://stackoverflow.com/questions/18116623

  •  23-06-2022
  •  | 
  •  

質問

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.

役に立ちましたか?

解決

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.

他のヒント

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. :(

That would suggest that the superView of that view doesn't have it's autoresizingMask set to FlexibleHeight (the up/down arrow in Interface Builder). If the superView don't resize your view won't change position.

try setting the auto resizing in the following manner. select the bottom view.

enter image description here

also remove auto layout if you are using. (uncheck auto layout from the File Inspector)

Hope this will help you.

Please check, you have tick out (by mistake, (by default it is ticked)) the Autoresizesubviews or not?

If Autoresize of the parent view is Off, then autoresize will not work.

Please check below image

enter image description here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top