title: UIScrollView behaves differently when embedded in a navigation controller
body: <p>In this view controller, I initialize a <code>UIScrollView</code>, add it to the hierarchy and add autolayout constraints in <code>viewDidLoad</code>, and add an image subview in <code>viewDidLayoutSubviews</code>.  If I assign this to a free-standing view in Storyboard, it behaves as expected (square scroll view with an image, I can scroll around).  However, if I embed this view in a navigation controller, making no other changes, I instead get a black screen that fills the window, sans image.</p>
  
  <p>Why is this happening, and how can I fix it?  I've seen other questions [1] [2] that suggest setting the content size.  However, I'm trying to use autolayout rather than setting the content size directly.</p>
  
  <p>Here is a minimal but complete example.  Again: works with freestanding view, not when embedded:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController, UIScrollViewDelegate {
  
      var scrollView: UIScrollView = UIScrollView(frame: CGRectZero)
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.scrollView.delegate = self
          self.scrollView.setTranslatesAutoresizingMaskIntoConstraints(false)
          self.view.addSubview(self.scrollView)
          self.scrollView.maximumZoomScale = 2
          self.scrollView.minimumZoomScale = 1
  
          self.view.setTranslatesAutoresizingMaskIntoConstraints(false)
  
          self.configureAutolayout()
      }
  
      override func viewDidLayoutSubviews() {
          if let x = UIImage(named: "photo.jpg") {
              let y = UIImageView(image: x)
              self.scrollView.addSubview(y)
          }
      }
  
      func configureAutolayout() {
  
          var constraint = NSLayoutConstraint(item: self.scrollView,
              attribute: .Leading,
              relatedBy: .Equal,
              toItem: self.view,
              attribute: .Leading,
              multiplier: 1,
              constant: 0)
          self.view.addConstraint(constraint)
  
          constraint = NSLayoutConstraint(item: self.scrollView,
              attribute: .Trailing,
              relatedBy: .Equal,
              toItem: self.view,
              attribute: .Trailing,
              multiplier: 1,
              constant: 0)
          self.view.addConstraint(constraint)
  
          constraint = NSLayoutConstraint(item: self.scrollView,
              attribute: .Top,
              relatedBy: .Equal,
              toItem: self.topLayoutGuide,
              attribute: .Bottom,
              multiplier: 1,
              constant: 0)
          self.view.addConstraint(constraint)
  
          constraint = NSLayoutConstraint(item: self.scrollView,
              attribute: .Height,
              relatedBy: .Equal,
              toItem: self.scrollView,
              attribute: .Width,
              multiplier: 1,
              constant: 0)
          self.view.addConstraint(constraint)
  
      }
  
      func viewForZoomingInScrollView(scrollView: UIScrollView!) -&gt; UIView! {
          return self.scrollView.subviews.first as UIView
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Removing the following line fixes one problem and introduces another:</p>
  
  <pre><code>self.view.setTranslatesAutoresizingMaskIntoConstraints(false)
  </code></pre>
  
  <p>The <code>UIScrollView</code>, with the image subview, now appear both in the independent view and when embedded in the navigation controller.  However, there is now an extra, unwanted space at the top of the scrollview of the embedded controller.  I thought that <code>TopLayoutGuide</code> was the appropriate view for alignment--is this not the case?</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>The inset problem was fixed by setting <code>self.automaticallyAdjustsScrollViewInsets</code> to <code>false</code>, as per this question [3].  It is not behaving as intended.</p>
  
  <p><strong>References:</strong></p>
  
  <p>[1] <a href="https://stackoverflow.com/questions/15840043/uiscrollview-not-scrolling-when-included-into-viewcontroller-embedded-into-a-nav">UIScrollView not scrolling when included into viewcontroller embedded into a navigation controller</a></p>
  
  <p>[2] <a href="https://stackoverflow.com/questions/22831968/uiscrollview-scroll-not-working-after-pushed-with-a-navigation-controller">UIScrollView scroll not working after pushed with a navigation controller</a></p>
  
  <p>[3] <a href="https://stackoverflow.com/questions/18798792/explaining-difference-between-automaticallyadjustsscrollviewinsets-extendedlayo">Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7</a></p>