title: UIPageViewController ignores Constraints when UIPageViewControllerTransitionStyle.Scroll
body: <p>I'm working on an app for my culinary Blog and wanted to achieve a look and feel like on the Apple AppStore Application. In my <em>DashboardViewController</em>:<strong>UIViewController</strong> Class I added a <em>headerView</em>:<strong>UIView</strong> and a <em>scrollView</em>:<strong>UIScrollView</strong>. The <em>headerView</em> is populated with my <em>HeaderPageViewController</em>:<strong>UIPageViewController</strong> as seen below. The Constraints are set to achieve a parallax effect on scrolling. 
  <img src="https://i.stack.imgur.com/8ZeZG.png" alt="View Hierarchy"></p>
  
  <p>To get some Content inside the Views my <em>HeaderPageViewController</em>'s View gets an <em>imageContentView</em>:<strong>UIImageView</strong> which is populated at runtime with the recipes of the month. Of course I added the usual constraints to the <em>imageContentView</em>, so it has the same size as the <em>HeaderPageViewController.view</em>!</p>
  
  <p>When initialising the <em>HeaderPageViewController</em> with <code>HeaderPageViewController(transitionStyle: UIPageViewControllerTransitionStyle.PageCurl, navigationOrientation: UIPageViewControllerNavigationOrientation.Horizontal, options: nil)</code> everything works fine. The Constraints of the <em>imageContentView</em> will be applied and the image grows and shrinks with it's ViewController inside the <em>headerView</em>. Whereas when I initialise the <em>HeaderPageViewController</em> with <code>HeaderPageViewController(transitionStyle: UIPageViewControllerTransitionStyle.Scroll, navigationOrientation: UIPageViewControllerNavigationOrientation.Horizontal, options: nil)</code> the <em>imageContentView</em> won't change with the size of the <em>headerView</em>.</p>
  
  <p>On the left side of that Image below you can see the effect using the initialiser with <em>UIPageViewControllerTransitionStyle.PageCurl</em>. On Scrolling the size of the headerPageViewController changes. on the right side you can see the result when setting <em>UIPageViewControllerTransitionStyle.Scroll</em> in the initialiser. I changed the BackgroundColor Property of the <em>HeaderPageViewController</em>, so you can better see the effect.</p>
  
  <p><img src="https://i.stack.imgur.com/XphzL.jpg" alt="Scrolling"></p>
  
  <hr>
  
  <p>I think I can boil it down to the Pagination of the <strong>UIPageViewController</strong>. When Displaying the Pagination the black Area is immediately visible, showing the Pagination on it as seen below. When scrolling up the View that contains the Pagination scales with my constraints, but apparently this is not the same View as the one I applied my constraints to.</p>
  
  <h2><img src="https://i.stack.imgur.com/fOUcJ.jpg" alt="Pagination"></h2>
  
  <p>This is the Important part of the <em>DashboardViewController</em> including my <strong>UIPageViewControllerDataSource</strong> function declaration.</p>
  
  <pre><code>class DashboardViewController: UIViewController, NSFetchedResultsControllerDelegate, UIPageViewControllerDataSource, UIPageViewControllerDelegate {
      [...]
  
      func populateHeaderView() {
          let headerPageViewController:HeaderPageViewController = HeaderPageViewController(transitionStyle: UIPageViewControllerTransitionStyle.Scroll, navigationOrientation: UIPageViewControllerNavigationOrientation.Horizontal, options: nil)
          //transitionStyle: UIPageViewControllerTransitionStyle.Scroll, navigationOrientation: UIPageViewControllerNavigationOrientation.Horizontal, options: nil
          headerPageViewController.view.backgroundColor = UIColor.blackColor()
          headerPageViewController.dataSource = self
          headerPageViewController.delegate = self
          let currentViewController:[UIViewController] = [self.viewControllerAtIndex(0)!]
          headerPageViewController.setViewControllers(currentViewController, direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
  
          self.addChildViewController(headerPageViewController)
          let headerPageView:UIView = headerPageViewController.view
          headerPageView.translatesAutoresizingMaskIntoConstraints = false
          headerPageView.contentMode = UIViewContentMode.ScaleAspectFill
          headerView.addSubview(headerPageView)
          headerPageViewController.didMoveToParentViewController(self)
  
          var headerPageViewContraints = [NSLayoutConstraint]()
          headerPageViewContraints.append(NSLayoutConstraint(item: headerPageView,
              attribute: NSLayoutAttribute.Top,
              relatedBy: NSLayoutRelation.Equal,
              toItem: headerView,
              attribute:NSLayoutAttribute.Top,
              multiplier: 1.0,
              constant: 0.0))
          headerPageViewContraints.append(NSLayoutConstraint(item: headerPageView,
              attribute: NSLayoutAttribute.Bottom,
              relatedBy: NSLayoutRelation.Equal,
              toItem: headerView,
              attribute:NSLayoutAttribute.Bottom,
              multiplier: 1.0,
              constant: 0.0))
          headerPageViewContraints.append(NSLayoutConstraint(item: headerPageView,
              attribute: NSLayoutAttribute.Leading,
              relatedBy: NSLayoutRelation.Equal,
              toItem: headerView,
              attribute:NSLayoutAttribute.Leading,
              multiplier: 1.0,
              constant: 0.0))
          headerPageViewContraints.append(NSLayoutConstraint(item: headerPageView,
              attribute: NSLayoutAttribute.Trailing,
              relatedBy: NSLayoutRelation.Equal,
              toItem: headerView,
              attribute:NSLayoutAttribute.Trailing,
              multiplier: 1.0,
              constant: 0.0))
          self.view.addConstraints(headerPageViewContraints)
      }
  
      // MARK: UIPageViewController DataSource
  
      func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -&gt; UIViewController? {
          if var index:UInt = (viewController as! HeaderPageViewController).index {
              if (index == 0) {
                  return nil
              }
              index--
  
              return self.viewControllerAtIndex(index)
          }
          return nil
      }
  
          func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -&gt; UIViewController? {
          if var index:UInt = (viewController as! HeaderPageViewController).index {
              index++
              if (Int(index) == headerRecipes.count) {
                  return nil
              }
              return self.viewControllerAtIndex(index)
          }
          return nil
      }
  
      /*
      func presentationCountForPageViewController(pageViewController: UIPageViewController) -&gt; Int {
          return headerRecipes.count
      }
  
      func presentationIndexForPageViewController(pageViewController: UIPageViewController) -&gt; Int {
          return 0
      }
      */
  
      // MARK: UIPageViewController Helper
  
      func getReasonableRecipesForHeaderPageViewController() {
          if(headerRecipes.count == 0) {
              headerRecipes = fetchedResultsController.fetchedObjects as! [Posts]
              if (headerRecipes.count &gt; 3) {
                  headerRecipes = Array(headerRecipes[0..&lt;3])
              }
          }
      }
  
      func viewControllerAtIndex(index:UInt) -&gt; UIViewController? {
          if (headerRecipes.count == 0 || Int(index) &gt;= headerRecipes.count) {
              return nil
          }
  
          let headerPageViewController:HeaderPageViewController = HeaderPageViewController()
          let recipe:Posts = headerRecipes[Int(index)] as Posts
          headerPageViewController.manageImageContentView(UIImageView(image: UIImage(data:recipe.featured_image!)))
          headerPageViewController.index = index
          return headerPageViewController
      }
  }
  </code></pre>
  
  <p>Also there is the complete <em>HeaderPageViewController</em> Class, which subclasses the <strong>UIPageViewController</strong>: </p>
  
  <pre><code>import Foundation
  import UIKit
  class HeaderPageViewController: UIPageViewController {
      var imageView:UIImageView = UIImageView()
      var index:UInt?
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
      func manageImageContentView(imageContentView:UIImageView) {
          imageView = imageContentView
          imageView.translatesAutoresizingMaskIntoConstraints = false
          imageView.contentMode = UIViewContentMode.ScaleAspectFill
          imageView.clipsToBounds = true
  
          self.view.addSubview(imageView)
  
          var headerViewContraints = [NSLayoutConstraint]()
          headerViewContraints.append(NSLayoutConstraint(item: imageView,
              attribute: NSLayoutAttribute.Top,
              relatedBy: NSLayoutRelation.Equal,
              toItem: self.topLayoutGuide,
              attribute:NSLayoutAttribute.Bottom,
              multiplier: 1.0,
              constant: 0.0))
          headerViewContraints.append(NSLayoutConstraint(item: imageView,
              attribute: NSLayoutAttribute.Bottom,
              relatedBy: NSLayoutRelation.Equal,
              toItem: self.view,
              attribute:NSLayoutAttribute.Bottom,
              multiplier: 1.0,
              constant: 0.0))
          headerViewContraints.append(NSLayoutConstraint(item: imageView,
              attribute: NSLayoutAttribute.Leading,
              relatedBy: NSLayoutRelation.Equal,
              toItem: self.view,
              attribute:NSLayoutAttribute.Leading,
              multiplier: 1.0,
              constant: 0.0))
          headerViewContraints.append(NSLayoutConstraint(item: imageView,
              attribute: NSLayoutAttribute.Trailing,
              relatedBy: NSLayoutRelation.Equal,
              toItem: self.view,
              attribute:NSLayoutAttribute.Trailing,
              multiplier: 1.0,
              constant: 0.0))
          self.view.addConstraints(headerViewContraints)
      }
  
      override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
  
      }
  }
  </code></pre>
  
  <p>If anyone of you has a hint to which view I have to apply my constraints or where I made a dumb mistake, please tell me.</p>