Skip to content
0:00 / 0:00

#autolayout#uikit#ios

UIKonf 2017 – Day 2 – Mischa Hildebrand – Auto Layout: From Trailing to Leading

UIKonf

3.4K subscribers • 2 videos on Hallway

YouTube
  • Recommended by 2 people: 2 in engineering communities.
  • A classic. People kept recommending it from 2017 to 2021.
  • Presented by Mischa Hildebrand
  • May be out of date. The tools, versions or practices it shows have likely moved on.

Intermediate. Assumes working knowledge.

4.3K views9 years ago2 recommendations

Mobile developmentiOS and SwiftUI

Mischa Hildebrand explains the mechanics of Auto Layout, constraints, and the layout cycle in iOS development.

"The tiny blue lines in Interface Builder look pretty self-explanatory: You can use them to define spacings between your views, give them a fixed width or a particular aspect ratio. But soon after creating your first simple layouts some of the blue lines turn red, indicating a conflicting layout. The more constraints you add the more pain it is to find the underlying problem. And it gets even worse when creating constraints in code or mixing Auto Layout with manual frame positioning. Soon enough you'll find yourself digging through the Apple docs, trying out every method that sounds like it could solve your layout problem: setNeedsLayout(), layoutIfNeeded(), layoutSubviews(), setNeedsUpdateConstraints(), updateConstraintsIfNeeded(), updateConstraints(), setNeedsDisplay()... just to name a few of them. They all sound kind of similar. Some work in one case but not in the other. You never know why. It's like a magic black box. The only way to dismantle this ""magic"" is to develop a deep understanding of the layout process, including the mathematics that's hidden behind the blue lines. This talk will give you the insight you need to effectively create beautiful layouts. You'll discover that constraints are linear equations by their true nature. You'll learn how the system resolves these equations to compute the actual frames and what the intrinsic content size is all about. You'll understand what constraint priorities are good for and how you can use them to make your layouts non-ambiguous. Despite dealing with the very foundation of Auto Layout you won't be confronted with much code in this talk. It includes many animated visuals to let you develop a good intuition for the layout engine."

Why it's here

2 people recommend this

What people say. Recommended as a great explanation of how Auto Layout and its layout cycle work under the hood.

u/vojnikMonin r/swift • Recommends

On “Having trouble understanding Auto Layout and constraints”

Watch this video, it has very good explanation of how autolayout works In your case the reason the view grows / shrinks is because you anchor it to the edges of your superview ( the view controller i am guessing) and that superview changes sizes on devices, if you want a constand dimension use width and height anchor and make it equal to a constant. After that you need to position it by using centerx or centery anchors or by the edges using top, bottom, leading, trailing anchors. link to this video

u/jan_olbrichin r/swift • Recommends

On “Good resources to learn Auto Layout?”

In case you like learning with videos. UIKonf 2017 had a great talk about the basics of AutoLayout: [video