title: Exclude navigation bar from iOS "safe area"
body: <p>In my iOS app, I have views rendered beneath the navigation bar. This is because the navigation bar is hidden until the user taps the screen.</p>
  
  <p>The screenshots below illustrate my problem. </p>
  
  <p>The "X" button is rendered beneath the iPhone X's notch and can hardly be seen. This is when I constrain the button's <code>topAnchor</code> to its <code>superview!.topAnchor</code>.</p>
  
  <blockquote>
    <p>Note that this works as intended for all devices except the iPhone X.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/nMuns.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nMuns.png" alt="enter image description here"></a></p>
  
  <p>The "X" button in this screenshot is anchored to its <code>superview!.safeAreaLayoutGuide.topAnchor</code> and renders below the navigation bar. This makes sense given Apple's documentation on <code>safeAreaLayoutGuide</code>:</p>
  
  <blockquote>
    <p>"this guide reflects the portion of the view that is not covered by navigation bars, tab bars, toolbars, and other ancestor views."</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/Zt1nh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Zt1nh.png" alt="enter image description here"></a></p>
  
  <p>However, I want the "X" button to render below the iPhone X's notch and underneath the navigation bar. Here's what it looks like when the navigation bar is hidden:</p>
  
  <p><a href="https://i.stack.imgur.com/ajRVu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ajRVu.png" alt="enter image description here"></a></p>
  
  <p>The "X" button should render right below the notch.</p>
  
  <p>So my question is: </p>
  
  <p><strong>Is there a way to exclude the navigation bar from a view's <code>safeAreaLayoutGuide</code>? And if not, what are my options, other than manually offsetting the button on iPhone X's.</strong></p>
  
  <blockquote>
    <p>Note that I'm doing everything programmatically. I no longer use Storyboards.</p>
  </blockquote>
  
  <p>Thanks!</p>