Re: Thoughts on autolayout
Re: Thoughts on autolayout
- Subject: Re: Thoughts on autolayout
- From: Stevo Brock <email@hidden>
- Date: Thu, 21 Apr 2016 14:50:53 -0700
I agree wholeheartedly. My process is very similar. It’s taken a bit of doing to get comfortable/efficient with autolayout, but I would *never* go back.
I also try very hard to do all my layouts entirely in IB so I have a single place to look for maintenance/enhancements.
In addition to what Bill described, I also do a lot of aligning leading and trailing constraints to views above such that I can change the horizontal spacing of entire columns of views by adjusting a single view/constraint near the top. For example, in a “table” of labels & text fields, with the labels set up to match leading, and width, simply by changing the label text, the entire layout reflows automatically.
On a recent project, I even came to terms with the constraint multiplier to have things scale across the range of iPhones, *and* started using the checkboxes that allow you to have different sets of constraints per size class. What I ended up with was a single layout that could look good on an iPhone 4 as well as an iPad, that even had different iPhone/iPad images with vastly different aspect ratios.
-Stevo Brock
Sunset Magicwerks, LLC
www.sunsetmagicwerks.com
818-478-9758
> On Apr 21, 2016, at 1:11 PM, Alex Kac <email@hidden> wrote:
>
> I’ve come to really like autolayout. I follow a similar set of steps that you do, but I’ve begun to use the Preview assistant to help me get my constraints right. It lets me test them in every language including the pseudo double length. Its fantastic.
>
>
>> On Apr 21, 2016, at 1:49 PM, Bill Cheeseman <email@hidden> wrote:
>>
>>
>>> On Apr 21, 2016, at 3:19 PM, Charles Srstka <email@hidden> wrote:
>>>
>>> Am I the only one who likes autolayout?
>>
>>
>> No, I like it, too. I developed an approach that I'm comfortable with, and if I stick to it I can get the job done quickly. Of course, trying to accomplish something I haven't done before requires a little more thought, but I find that I can figure it out pretty quickly. It almost comes natural now.
>>
>> I use IB exclusively. My approach goes like this, on a one-window-at-a-time or one-view-at-a-time basis:
>>
>> 1. Drag all the views and controls onto the canvas and drop them more or less where I want them to end up. Don't waste any time trying to align them or make them the right size exactly -- just get position and size approximately right and move on. Leave it looking a little ragged. Above all, don't create any constraints yet.
>>
>> 2. Write enough of the application code to get a sense whether the layout needs to be changed. Change it as needed, but again don't waste any time getting it exactly right and don't create any constraints yet.
>>
>> 3. When the design feels like its ready to be frozen, create the constraints. DO NOT move the controls and views into the exact place they belong and then add constraints -- instead, do it the other way around: create the constraints first and then tell the controls and views to obey them. It will be much easier to see that they all moved into the right place, because they will all move a relatively short distance. More on this step below.
>>
>> 4. Every time you tell a window or view to obey new constraints, watch very carefully. If the controls and views move or resize in unexpected ways, or disappear completely, immediately choose undo to get back to where you were (with all the controls and views in approximately the right locations). Then figure out which constraint you left out or got wrong, and fix it. Repeatedly undo and fix as needed.
>>
>> 5. When you think you're done, lock the constraints down and do a lot of window resizing, divider dragging, and so on to test them.
>>
>> More on step 3. I create constraints the way I read: start at the top left corner, move item by item to the right, then move down one "row" and start at the left again, and so on until I reach the bottom right corner. This leads to some useful consistencies to help my brain figure out why something went wrong. (a) For example, it is often only the leftmost button in the top "row" of controls that needs a top constraint to the superview; the other buttons in that "row" will have their vertical dimension controlled by baseline or center alignment, or something similar. (b) Horizontal constraints are easily made complete, because I account for each piece one step at a time from left to right: leading constraint, width constraint, trailing constraint, etc. (c) I don't worry about hugging priorities and the like until all else fails, because the default priorities are designed to be right for most situations.
>>
>
> Alex Kac - El capitán
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden