<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Autolayout on A&#43; programming moments</title>
    <link>https://aplus.rs/tags/autolayout/</link>
    <description>Recent content in Autolayout on A&#43; programming moments</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 28 Mar 2020 12:01:00 +0000</lastBuildDate>
    
	<atom:link href="https://aplus.rs/tags/autolayout/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>No headache: auto layout tips in Interface Builder</title>
      <link>https://aplus.rs/2020/no-headache-auto-layout-tips/</link>
      <pubDate>Sat, 28 Mar 2020 12:01:00 +0000</pubDate>
      
      <guid>https://aplus.rs/2020/no-headache-auto-layout-tips/</guid>
      <description>&lt;p&gt;I wrote previously how to setup your main views so that &lt;a href=&#34;https://aplus.rs/2020/proper-embedding-in-the-world-of-increasingly-diverse-safeareainsets/&#34;&gt;embedding properly respects safe areas&lt;/a&gt; on whatever device it’s being run on.
The key thing: setup inner constraints towards VC.view to use superview &lt;em&gt;margins&lt;/em&gt;. Easiest way to do this is to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;add one UIView as direct child of VC.view&lt;/li&gt;
&lt;li&gt;setup constraints of that view so its edges are all connected to VC.view’s margins&lt;/li&gt;
&lt;li&gt;All your content then goes into that “real” content view and you are set&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This will solve at least 90% of layouts you’ll ever need to do.&lt;/p&gt;
&lt;p&gt;Don’t forget an &lt;a href=&#34;https://aplus.rs/2017/one-solution-for-90pct-auto-layout/&#34;&gt;older tip about setting priority 999&lt;/a&gt; for some of the sides of realContentView.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Another great guideline: when you have a series of child &lt;em&gt;sibling&lt;/em&gt; views inside a container, either horizontal or vertical, your job will be much easier if you &lt;em&gt;prioritise making constraints among siblings&lt;/em&gt; and avoid superview as much as possible.&lt;/p&gt;
&lt;p&gt;Between vertical siblings, it looks like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2020/ib-auto-layout/sibling-subview-in-container.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Few things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Make sure to use default (standard) spacing because then you follow HIG and app will generally look better.&lt;/li&gt;
&lt;li&gt;First sibling in a (vertical) row will have constraints to leading, top and trailing edges of the superview.&lt;/li&gt;
&lt;li&gt;The following child views will align each other.&lt;/li&gt;
&lt;li&gt;The last child will align to superview’s bottom edge.&lt;/li&gt;
&lt;li&gt;By doing this, you will have just one place to change spacing for all the children.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Or you can use &lt;code&gt;UIStackView&lt;/code&gt; for this, although I find that component useful only with repeating identical views. In all other cases it’s more trouble than it’s worth. Additionally in case you want to create a layout that autosizes per &lt;a href=&#34;https://developer.apple.com/documentation/uikit/uicontentsizecategory&#34;&gt;contentSizeCategory&lt;/a&gt;, then stack views can make that impossible, depending on the layout.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Speaking of dynamic type, always, &lt;em&gt;always&lt;/em&gt; use Text styles for all your &lt;code&gt;UILabel&lt;/code&gt;, &lt;code&gt;UITextField&lt;/code&gt;, &lt;code&gt;UITextView&lt;/code&gt; etc. And make sure to set this “Automatically Adjusts Font” checkbox:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2020/ib-auto-layout/label-dynamictype.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;and&lt;/em&gt; make sure to set Lines: 0 so the text is fully visible regardless what content category size is used by end customer.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;UIButton&lt;/code&gt; sadly does not have this option, but you can enforce it for its &lt;code&gt;titleLabel&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2020/ib-auto-layout/button-dynamic-type.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;You’ll need to include this simple extension somewhere in your code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;kd&#34;&gt;extension&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;UIButton&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;	&lt;span class=&#34;c1&#34;&gt;///	Allows automatic response on contentSize change (dynamic type)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kr&#34;&gt;@IBInspectable&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;kd&#34;&gt;var&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;adjustsFontForContentSizeCategory&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;Bool&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kr&#34;&gt;set&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;titleLabel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;?.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;adjustsFontForContentSizeCategory&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;newValue&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;kr&#34;&gt;get&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;            &lt;span class=&#34;k&#34;&gt;return&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;self&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;titleLabel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;?.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;adjustsFontForContentSizeCategory&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;??&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;false&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;for that option to appear in Interface Builder.&lt;/p&gt;
&lt;p&gt;For buttons, also make sure to use &lt;code&gt;greaterThanOrEqual&lt;/code&gt; height constraint:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2020/ib-auto-layout/button-height-dynamic-type.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Final tip for today: IB does not have easy ability to setup rounded corners that are so prevalent in many designs, especially for buttons and various containers. Thus many devs resort to using this in code:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;textView.layer.borderWidth = 1
textView.layer.borderColor = UIColor.lightGrey.cgColor
textView.layer.cornerRadius = 4
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can use runtime attributes for this, in the Identity panel (rather strange place for it):&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2020/ib-auto-layout/runtime-attributes.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;The code above is almost always followed by this file as well, to actually have those rounded corners rendered:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;textView.layer.masksToBounds = true
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This line is also not needed as the same thing is achieved by simply setting “Clips to bounds” on View subsection in the Attributes panel.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2020/ib-auto-layout/clips-to-bounds.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>One solution for 90% of Auto Layout exceptions</title>
      <link>https://aplus.rs/2017/one-solution-for-90pct-auto-layout/</link>
      <pubDate>Sun, 15 Oct 2017 10:49:40 +0000</pubDate>
      
      <guid>https://aplus.rs/2017/one-solution-for-90pct-auto-layout/</guid>
      <description>&lt;p&gt;How many times have you seen this output in Xcode console:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;(
    &amp;#34;&amp;lt; NSAutoresizingMaskLayoutConstraint:0x60c00028d5c0 h=-&amp;amp;- v=-&amp;amp;- _UIVisualEffectContentView:0x7faa9f7054e0.width == UIVisualEffectView:0x7faa9f705090.width   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x60000028eb50 UIView:0x7faa9f7056e0.trailing == UISegmentedControl:0x7faa9f1607d0.trailing   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x60000028ebf0 UIView:0x7faa9f7056e0.leading == UISegmentedControl:0x7faa9f1607d0.leading   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x60000028ec90 UISegmentedControl:0x7faa9f1607d0.leading == _UIVisualEffectContentView:0x7faa9f7054e0.leadingMargin   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x60000028ece0 _UIVisualEffectContentView:0x7faa9f7054e0.trailingMargin == UISegmentedControl:0x7faa9f1607d0.trailing   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x60000028f460 H:|-(0)-[UIVisualEffectView:0x7faa9f705090]   (active, names: &amp;#39;|&amp;#39;:UIView:0x7faa9f704eb0 )&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x60000028f4b0 H:[UIVisualEffectView:0x7faa9f705090]-(0)-|   (active, names: &amp;#39;|&amp;#39;:UIView:0x7faa9f704eb0 )&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x60c00028cdf0 &amp;#39;UIView-Encapsulated-Layout-Width&amp;#39; UIView:0x7faa9f704eb0.width == 0   (active)&amp;gt;&amp;#34;
)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Here’s another, much simpler example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;(
    &amp;#34;&amp;lt; NSLayoutConstraint:0x608000291990 H:[UITableView:0x7f8207122000]-(8)-|   (active, names: &amp;#39;|&amp;#39;:UIView:0x7f8206c3f9c0 )&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x6080002919e0 H:|-(8)-[UITableView:0x7f8207122000]   (active, names: &amp;#39;|&amp;#39;:UIView:0x7f8206c3f9c0 )&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x600000294be0 &amp;#39;UIView-Encapsulated-Layout-Width&amp;#39; UIView:0x7f8206c3f9c0.width == 0   (active)&amp;gt;&amp;#34;
)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Or another variant:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;2017-10-11 12:39:44.819705+0200 Stage[7072:165152] [LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don&amp;#39;t want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don&amp;#39;t expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
	(Note: If you&amp;#39;re seeing NSAutoresizingMaskLayoutConstraints that you don&amp;#39;t understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    &amp;#34;&amp;lt; NSAutoresizingMaskLayoutConstraint:0x60c00068cd50 h=--&amp;amp; v=--&amp;amp; Stage.LoadingView:0x7fe7ae499850.width == 0   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x600000687b20 UILabel:0x7fe7ae499c50&amp;#39;Please wait...&amp;#39;.centerX == Stage.LoadingView:0x7fe7ae499850.centerXWithinMargins   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x600000680960 UILabel:0x7fe7ae499c50&amp;#39;Please wait...&amp;#39;.leading &amp;gt;= Stage.LoadingView:0x7fe7ae499850.leadingMargin   (active)&amp;gt;&amp;#34;
)

Will attempt to recover by breaking constraint 
&amp;lt; NSLayoutConstraint:0x600000680960 UILabel:0x7fe7ae499c50&amp;#39;Sačekajte...&amp;#39;.leading &amp;gt;= Stage.LoadingView:0x7fe7ae499850.leadingMargin   (active)&amp;gt;

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I left the hints Apple developers output only in the last example, since it’s always the same text.&lt;/p&gt;
&lt;p&gt;So, what’s the issue here and how to solve it?&lt;/p&gt;
&lt;h3 id=&#34;no-its-not-that&#34;&gt;No, it’s not that…&lt;/h3&gt;
&lt;p&gt;Tricky red herring:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;(Note: If you&amp;#39;re seeing NSAutoresizingMaskLayoutConstraints that you don&amp;#39;t understand, 
refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In my case at least, it’s never that – I have enough experience that I rarely forget to set this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-swift&#34; data-lang=&#34;swift&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;view&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;translatesAutoresizingMaskIntoConstraints&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;kc&#34;&gt;false&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;its-actually-this&#34;&gt;…it’s actually this&lt;/h3&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;#34;&amp;lt; NSLayoutConstraint:0x600000294be0 &amp;#39;UIView-Encapsulated-Layout-Width&amp;#39; UIView:0x7f8206c3f9c0.width == 0   (active)&amp;gt;&amp;#34;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;plus your constraints. &lt;code&gt;UIView-Encapsulated-Layout-Width&lt;/code&gt; and its counterpart &lt;code&gt;UIView-Encapsulated-Layout-Height&lt;/code&gt; is an internal UIKit thingie that’s outside your reach. You can’t control it, you can’t access it, you can’t override it.&lt;/p&gt;
&lt;p&gt;This is the constraint used by UIKit to control the outside size of the views where you as non-Apple developer work in. For instance on &lt;code&gt;UITableViewCell&lt;/code&gt;, where actual width and height is set internally by &lt;code&gt;UITableView&lt;/code&gt;. It’s found on their container views, like when you setup your view as say &lt;code&gt;UITableView.backgroundView&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;That’s exactly what’s happening here:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;(
    &amp;#34;&amp;lt; NSAutoresizingMaskLayoutConstraint:0x60c00068cd50 h=--&amp;amp; v=--&amp;amp; Stage.LoadingView:0x7fe7ae499850.width == 0   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x600000687b20 UILabel:0x7fe7ae499c50&amp;#39;Please wait...&amp;#39;.centerX == Stage.LoadingView:0x7fe7ae499850.centerXWithinMargins   (active)&amp;gt;&amp;#34;,
    &amp;#34;&amp;lt; NSLayoutConstraint:0x600000680960 UILabel:0x7fe7ae499c50&amp;#39;Please wait...&amp;#39;.leading &amp;gt;= Stage.LoadingView:0x7fe7ae499850.leadingMargin   (active)&amp;gt;&amp;#34;
)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;I have a simple view with the &lt;code&gt;UILabel&lt;/code&gt; x-centered within margins and with both sides of label set to be &amp;gt;= of its superview horizontal margins.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2017/al-centerx-with-margins.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Those margins are 8pt, so my &lt;code&gt;LoadingView&lt;/code&gt; requires at least 16pt wide container, in the edge case where &lt;code&gt;label.text = nil&lt;/code&gt;. However, in this particular moment, UITableView has its width set to 0:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;lt; NSAutoresizingMaskLayoutConstraint:0x60c00068cd50 h=--&amp;amp; v=--&amp;amp; Stage.LoadingView:0x7fe7ae499850.width == 0   (active)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;which causes this Auto Layout exception.&lt;/p&gt;
&lt;p&gt;Why?&lt;/p&gt;
&lt;p&gt;Label’s both leading and trailing constraint have priority = 1000 plus the center-X-to-superview constraint is also set to priority=1000. Thus all 3 &lt;em&gt;must&lt;/em&gt; be obeyed, which requires a minimum of 16pt-wide container which can’t fit into 0-width specified by UITableView, hence &lt;em&gt;ka-boom&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;“But everything looks fine on the screen, UITableView is not 0-width” I hear you say. Yes, that’s true - at the end of transition that happens while this particular view is being shown. But for way too brief moment, UITableView was 0-wide sometime along the way and that caused the error output.&lt;/p&gt;
&lt;p&gt;Solution? Give the Auto Layout some degree of freedom.&lt;/p&gt;
&lt;p&gt;By settings &lt;em&gt;both&lt;/em&gt; leading and trailing constraint’s priority to 999, you allow Auto Layout engine to temporary ignore the margins.&lt;/p&gt;
&lt;p&gt;That’s my greatest Auto Layout trick:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;set &lt;strong&gt;priority to 999&lt;/strong&gt; for half of your constraints in horizontal and/or vertical dimension&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Here’s another example, with self-sizing UITableViewCell:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://aplus.rs/images/2017/al-baseline-2.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Label showing actual date value is bottom aligned to superview’s margin thus requires at least 8pt at the bottom. It’s also baseline-aligned to the &lt;em&gt;Date&lt;/em&gt; label next to it, from where there’s constraint chain that goes up the vertical axis right until the ID label’s top aligned to superview’s top margin. Plus I have set both &lt;em&gt;Date&lt;/em&gt; and &lt;em&gt;ID&lt;/em&gt; label’s compression resistance to 1000.&lt;/p&gt;
&lt;p&gt;When you do &lt;code&gt;insertRows&lt;/code&gt; or &lt;code&gt;deleteRows&lt;/code&gt; with certain animation types, UIKit will animate the row height from 0 to full height or back. At the 0-end of that animation, the layout equations are impossible to solve if entire vertical axis is set to priority=1000. But lower just one constraint to 999 – say that bottom space to superview margin – and all is fine; the content will just drop-down, outside the cell’s bounds.&lt;/p&gt;
&lt;p&gt;Hence the promised one solution to most of your head-scratching Auto Layout issues: &lt;em&gt;for every view you add that has a connection to a superview that you do not control, make sure that one side of that connection has priority less than 1000&lt;/em&gt;. I usually set trailing and bottom constraint to 999 + make sure that the said superview has &lt;code&gt;clipsToBounds=true&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Happy layout-ing.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>