Skip to content

Instantly share code, notes, and snippets.

@m4c1ek
Last active September 16, 2016 20:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4c1ek/7bfc388a8144ddbeaf5d to your computer and use it in GitHub Desktop.
Save m4c1ek/7bfc388a8144ddbeaf5d to your computer and use it in GitHub Desktop.
AutoLayout

NSLog(@"%@", [[[UIApplication sharedApplication] keyWindow] performSelector:@selector(_autolayoutTrace)]);
po [[UIWindow keyWindow] _autolayoutTrace];

Cocoa layout example

UIViewShowAlignmentRects YES
UIViewShowAlignmentRects

Autolayout performance

http://constraints.cs.washington.edu/cassowary/
"the amount of time it takes to solve the constraint system increases disproportionally relative to the number of constraints involved."

http://pilky.me/36/

A flat hierarchy of views, absolutely positioned in the root view
A flat hierarchy of views, relatively positioned to each other
flat, absolute relative

A nested hierarchy of views, relatively positioned to each other
nested relative

compare all
Let's look at our flat layout. While the position constraints need to be on the root view, the size constraints don't. I changed the code so that the size constraints were being added to the subview instead, and got the following results:
size contrainsts in subview

all the constraints relating to a view can be put in the immediate superview, dramatically increasing the locality. The graph below shows just how significant an improvement this gives.
nested layout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment