Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Auto Layout? Oh boy!
Search
Cesare Rocchi
May 02, 2013
Technology
1
200
Auto Layout? Oh boy!
Slides of my presentation "Auto Layout? Oh boy!" at UIKonf
Cesare Rocchi
May 02, 2013
Tweet
Share
More Decks by Cesare Rocchi
See All by Cesare Rocchi
In the customer's shoes
funkyboy
0
120
What the heck is JavaScriptCore?
funkyboy
0
110
The new WebKit is awesome
funkyboy
1
320
The new WebKit is AWESOME
funkyboy
0
480
Designing with Cognitive Science in Mind
funkyboy
0
130
The new WebKit is AWESOME
funkyboy
0
160
Choosing a back end for your mobile app:
funkyboy
0
620
Apps and Mental Models
funkyboy
0
200
Auto Layout? Oh boy!
funkyboy
0
130
Other Decks in Technology
See All in Technology
WINTICKETアプリで実現した高可用性と高速リリースを支えるエコシステム / winticket-eco-system
cyberagentdevelopers
PRO
1
190
Datachain会社紹介資料(2024年11月) / Company Deck
datachain
3
16k
AWS CDKでデータリストアの運用、どのように設計する?~Aurora・EFSの実践事例を紹介~/aws-cdk-data-restore-aurora-efs
mhrtech
4
650
ネット広告に未来はあるか?「3rd Party Cookie廃止とPrivacy Sandboxの効果検証の裏側」 / third-party-cookie-privacy
cyberagentdevelopers
PRO
1
130
現地でMeet Upをやる場合の注意点〜反省点を添えて〜
shotashiratori
0
530
10分でわかるfreee エンジニア向け会社説明資料
freee
18
520k
omakaseしないための.rubocop.yml のつくりかた / How to Build Your .rubocop.yml to Avoid Omakase #kaigionrails
linkers_tech
3
740
Vueで Webコンポーネントを作って Reactで使う / 20241030-cloudsign-vuefes_after_night
bengo4com
4
2.5k
Jr. Championsになって、強く連携しながらAWSをもっと使いたい!~AWSに対する期待と行動~
amixedcolor
0
190
visionOSでの空間表現実装とImmersive Video表示について / ai-immersive-visionos
cyberagentdevelopers
PRO
1
110
「視座」の上げ方が成人発達理論にわかりやすくまとまってた / think_ perspective_hidden_dimensions
shuzon
2
4.8k
ユーザーの購買行動モデリングとその分析 / dsc-purchase-analysis
cyberagentdevelopers
PRO
2
100
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Designing for Performance
lara
604
68k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
790
Unsuck your backbone
ammeep
668
57k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Side Projects
sachag
452
42k
Practical Orchestrator
shlominoach
186
10k
Facilitating Awesome Meetings
lara
49
6k
Transcript
Auto Layout? Oh boy! Rocchi Cesare _funkyboy funkyboy
Outline History Frames Spring&Struts Auto layout
Who am I?
UX designer and developer
Who are you?
Giveaway
None
Lyrics
“Ring! Ring! It's 7:00 A.M.! Move y'self to go again”
“Ring! Ring! It's 7:00 A.M.! Move y'self to go again”
The Magnificent Seven - The Clash
A bit of history
A bit of history
A bit of history
A bit of history
A bit of history
None
None
What is layout?
What is layout? Position Size
Web people have CSS
http://mediaqueri.es
http://joshemerson.co.uk/rsd/
In the beginning ...
Frames UIView *newView = [[UIView alloc] initWithFrame: CGRectMake(10, 10, 100,
100)]; [self.view addSubview:newView];
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;
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;
Spring & Struts
Spring & Struts Autosizing mask
Spring & Struts Autosizing mask How do I change when
superview changes?
Spring & Struts
Spring & Struts
Spring & Struts self.view.autoresizingMask =
Spring & Struts UIViewAutoresizingFlexibleWidth UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleLeftMargin UIViewAutoresizingFlexibleRightMargin UIViewAutoresizingFlexibleTopMargin UIViewAutoresizingFlexibleBottomMargin self.view.autoresizingMask
=
Auto Layout
Mental shift
Impacts your life
Wife: “Honey are you still working with that auto layout
thing?”
Wife: “Honey are you still working with that auto layout
thing?” Me: “Yeah, how do you know?”
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”.
You DON’T setFrame: anymore
You DON’T setFrame: anymore You DECLARE a layout
You express relations between elements
constraint3 constraint4 constraint1 constraint2
constraint3 constraint4 constraint1 constraint2
constraint3 constraint4 constraint1 constraint2
?
Linear equations
ax + by = c Linear equations
ax + by = c Linear equations
ax + by = c 2x + 2y = 4
Linear equations
ax + by = c 2x + 2y = 4
=> [x = 1, y = 1] Linear equations
ax + by = c 2x + 2y = 4
=> [x = 1, y = 1] 2(x+5)-7 = 3(x-2) Linear equations
ax + by = c 2x + 2y = 4
=> [x = 1, y = 1] 2(x+5)-7 = 3(x-2) => [x = 9] Linear equations
0x + 1 = 2
Linear equations One solution No solution Infinite solutions
One solution
One solution “Hey lady, you got the love I need
...”
One solution “Hey lady, you got the love I need
...” Over the Hills and Far Away - Led Zeppelin
No solution
“Pleased to meet you hope you guess my name ...”
No solution
“Pleased to meet you hope you guess my name ...”
No solution Sympathy For The Devil - The Rolling Stones
Infinite solutions
“It's gettin' dark, too dark to see ...” Infinite solutions
“It's gettin' dark, too dark to see ...” Infinite solutions
Knockin' on Heaven's Door - Bob Dylan
Geometry helps
Geometry helps One solution x -2y = -1 4x +
3y = 7
Geometry helps No solution 3x + 2y = 12 3x
+ 2y = 6
Geometry helps Infinite solutions y = 10x + 4 -30x
- 12 = -3y
Likes one solution scenarios Multiple solutions => ambiguous layout No
solution => conflicting constraints
No order in grinding ...
No order in grinding ... Priorities
“Left margin is always 20” “Top margin is always 20”
Let’s see
“Left edge is 20” “Top edge is 20” “Width is
100” “Height is 100”
Enough IB
NSLayoutConstraint
[NSLayoutConstraint constraintWithItem:newElement
[NSLayoutConstraint constraintWithItem:newElement attribute:NSLayoutAttributeLeft
[NSLayoutConstraint constraintWithItem:newElement attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual
[NSLayoutConstraint constraintWithItem:newElement attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:[newElement superview]
[NSLayoutConstraint constraintWithItem:newElement attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:[newElement superview] attribute:NSLayoutAttributeLeft
[NSLayoutConstraint constraintWithItem:newElement attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:[newElement superview] attribute:NSLayoutAttributeLeft multiplier:1.0
[NSLayoutConstraint constraintWithItem:newElement attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:[newElement superview] attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
More complex example
Zen
Zen NSArray *constraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[newEl]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(newEl)];
Zen @"V:|[newElement]-100-|"
Zen @"V:[btn1]-[btn2]"
Zen @"V:[btn1]-100-[btn2]"
Zen @"[btn(>=100)]"
Zen @"[btn(>=100@500)]"
Zen @"[btn1(>=80, <=120)]"
Animation
Alternative
Alternative https://github.com/RolandasRazma/RRAutoLayout if(!NSClassFromString(@"NSLayoutConstraint")) { objc_registerClassPair( objc_allocateClassPair( [RRLayoutConstraint class], "NSLayoutConstraint", 0));
}
DON’T think in terms of frames
Should I use Auto Layout?
“The answer my friend is ...”
“The answer my friend is ...” Blowin' In The Wind
- Bob Dylan
Summing up Did blocks substitute delegates?
Thank you!
Coordinates twitter.com/_funkyboy app.net/funkyboy
[email protected]
http://studiomagnolia.com