Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Auto Layout? Oh boy ..

Auto Layout? Oh boy ..

After making fun of Android developers because they have to support a plethora of resolutions, the storm has gotten into the iOS community as well. First there was the retina, which brought designers and developers to account for a new resolution, exactly the double of the previous one, and was not a huge deal. With the announcement of the iPhone5 a new form factor was introduced along with a new software tool to deal with fluid user interfaces: autolayout. Developers familiar with the good old “Springs & Struts” approach have had a great deal of issues in getting acquainted with autolayout.
In this presentation I will show how to progressively move away from autosizing masks and get familiar with Autolayout constraint-based mechanism. First I’ll show how to use it in Interface Builders and how to deal with conflicting constraints. Then I’ll move on to code, to show how to achieve the intended results using the new API introduced in iOS6. Finally I’ll give some example that uses ASCII-Art format string to declare constraints.
The goal of the talk is to highlight the conceptual and technical differences between Spring & Struts and Autolayout, to make easier the potentially complex process of porting an application from the first to the second.

Cesare Rocchi

March 15, 2013
Tweet

More Decks by Cesare Rocchi

Other Decks in Programming

Transcript

  1. 240x320 320x480 480x800 640x360 1280x720 1280x800 1080x1920 824x1200 768x1024 600x800

    960x640 960x540 1280x768 854x480 640x480 2560x1600 1136x768
  2. Frames UIView *newView = [[UIView alloc] initWithFrame: CGRectMake(10, 10, 100,

    100)]; [self.view addSubview:newView]; CGRect frame = newView.frame; frame.size.height = 200; frame.size.width = 200; frame.origin.x = 20; frame.origin.y = 20; newView.frame = frame;
  3. Frames UIView *newView = [[UIView alloc] initWithFrame: CGRectMake(10, 10, 100,

    100)]; [self.view addSubview:newView]; CGRect frame = newView.frame; frame.size.height = 200; frame.size.width = 200; frame.origin.x = 20; frame.origin.y = 20; newView.frame = frame; newView.center = newView.superview.center;
  4. Frames #define PADDING 20 CGRect supFrame = newView.superview.frame; CGRect frame

    = newView.frame; frame.size.height = supFrame.size.height - PADDING; frame.size.width = supFrame.size.width - PADDING; frame.origin.x = PADDING; frame.origin.y = PADDING; newView.frame = frame;
  5. Wife: “Honey are you still working with that auto layout

    thing?” Me: “Yeah, how do you know?”
  6. Wife: “Honey are you still working with that auto layout

    thing?” Me: “Yeah, how do you know?” Wife: “Because I am hearing more ‘f*ck’ and ‘sh!t’ than usual”.
  7. ?

  8. ax + by = c 2x + 2y = 4

    Linear equations
  9. ax + by = c 2x + 2y = 4

    => [x = 1, y = 1] Linear equations
  10. ax + by = c 2x + 2y = 4

    => [x = 1, y = 1] 2(x+5)-7 = 3(x-2) Linear equations
  11. ax + by = c 2x + 2y = 4

    => [x = 1, y = 1] 2(x+5)-7 = 3(x-2) => [x = 9] Linear equations
  12. One solution “Hey lady, you got the love I need

    ...” Over the Hills and Far Away - Led Zeppelin
  13. “Pleased to meet you hope you guess my name ...”

    No solution Sympathy For The Devil - The Rolling Stones
  14. “Left edge of X is 20” “Top edge of X

    is 20” “Width is 100” “Height is 100”
  15. Zen