Chapters

Hide chapters

Auto Layout by Tutorials

First Edition · iOS 13 · Swift 5.1 · Xcode 11

Section II: Intermediate Auto Layout

Section 2: 10 chapters
Show chapters Hide chapters

Section III: Advanced Auto Layout

Section 3: 6 chapters
Show chapters Hide chapters

13. Common Auto Layout Issues
Written by Libranner Santos

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Auto Layout is great, but it’s not a magic formula for creating bug-free interfaces. With Auto Layout, you’ll occasionally run into problems. For instance, your layout may too few constraints, too many constraints or conflicting constraints. Although the Auto Layout Engine will try to solve most of these problems for you, it’s crucial to understand how to handle them.

Understanding and solving Auto Layout issues

Under the hood, the Auto Layout Engine reads each of your constraints as a formula for calculating the position and size of your views. When the Auto Layout Engine is unable to satisfy all of the constraints, you’ll receive an error.

There are three types of errors you’ll encounter while working with Auto Layout:

  • Logical Errors: These types of errors usually occur when you inadvertently set up incorrect constraints. Maybe you entered incorrect values for the constants, choose the wrong relationship between the elements or didn’t take into account the different orientations and screen sizes.

  • Unsatisfiable Constraints: You’ll get these errors when it’s impossible for the Auto Layout Engine to calculate a solution. A simple example is when you set one view to have a width < 20 and a width = 100. Since both of those constraints cannot be true at the same time, you’ll get an error.

  • Ambiguous Constraints: When the Auto Layout Engine is trying to satisfy multiple constraints, and there’s more than one possible solution, you’ll get this type of error. When this happens, the engine will randomly select a solution, which may produce unexpected results with your UI.

It’s time to see how these issues look in a real project, starting with Unsatisfiable Constraints.

Unsatisfiable Constraints

Open the starter project for this chapter and build and run.

How to read the logs

Look at the console, and you’ll see some useful information. What you’re seeing is a combination of informative text, constraints in visual format language and even some helpful suggestions:

Symbolic Breakpoints

When you create a Symbolic Breakpoint at UIViewAlertForUnsatisfiableConstraints, the app will stop running if it finds an unsatisfiable constraint. This is useful because sometimes the app may appear OK, when in fact, it has some issues you need to address.

Using Interface Builder to solve conflicts

Open Main.storyboard. In the document outline, click the red circle with an arrow at the right of the Game Scene, and you’ll see a list of the conflicting constraints.

Ambiguous layouts

When the Auto Layout Engine arrives at multiple solutions for a system of constraints, you’ll have what’s known as an ambiguous layout.

UIView debug methods

UIView comes with four useful methods that you can use for debugging your Auto Layout issues:

Dealing with ambiguous layouts

Go back to the starter project and build and run.

Visual debugging

To solve the remaining issue, you’ll use the Debug View Hierarchy, which gives a visual way to look at how the layout is structured.

View hierarchy toolbar

So what does this new toolbar do? From left to right:

Handling runtime issues

Using the memory address copied from the layout trace, paste it on the filter located at the bottom-left side of the screen.

Common performance issues

The Auto Layout Engines does a lot of things for you. It acts as a dependency cache manager, making things faster, and Apple makes performance-related improvements nearly every year. Nonetheless, you have to be aware of how it works to avoid the unnecessary use of resources.

Churning

Churning is a common issue and one that can easily fly above any developer’s head. It usually happens when you create multiple constraints — many times without them being necessary.

Layout feedback loop

Until now, you haven’t seen the second tab of the app: History.

Key points

  • There are three main types of Auto Layout issues: ambiguous layouts, unsatisfiable constraints and logic errors.
  • You can solve Auto Layout issues faster using UIView methods, Debug View Hierarchy and Interface Builder.
  • To avoid performance issues, you need to understand how the Render Loop and Auto Layout Engine works.
Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now