I have read dozens of webpages perspectives. Many say that if I am
using auto layout correctly, I should not need to explicitly state the
size of my view objects. Yet, auto layout seems to almost demand
exactly that, explicit size constraints! If I do not give them, auto
layout says my image and view sizes are "ambiguous".
It is important to distinguish between normal views and scroll views here. For normal views, you can lay out your content and constrain your views to edges of the super view or to surrounding views and this works.
For scroll views, it is necessary for Auto Layout to be able to compute the size of the contentView. This can be done in one of 2 ways. You either 1) explicitly set the width and height of your contentView with constraints, in which case you can now treat the contentView as a normal view and lay it out accordingly OR 2) you size and constrain all of the objects in the contentView explicitly so that the size of the contentView can be computed from the sizes of the objects it contains. In other words, you either fix the size of the contentView so that AutoLayout can place the other items, or you fix the size of the items so that Auto Layout can compute the size of the contentView.
I would also like to know what auto layout will do when my conatraints
are loaded on a retina display. Will my 300x90 image suddenly be half
the size? Will a view I pin 70 from the top now be covered by a
navigation bar? Most auto layout tutorials focus on how to use
constraints, not how my 300x90 image will be manipulated by the iOS on
different devices.
Constraints are done in points, not pixels. Your 300x90
image is 300
points by 90
points. It will be sized properly for all devices. If you provide additional image assets for @2X and @3X, it will even use the proper image for each device.
It seems like, if they wanted the view to be fluid then I should be
specifying percents, not specific pixel measurements!
You can use the multiplier property of the constraints to achieve percents. For instance, if you want your image width to be 50% of the width of the super view, set an Equal Widths constraint between the image view and its super view and then change the multiplier to be 0.5
.