title: UIScrollView and Page Control, Page Control Disrupting View
body: <p>So, I know its been done many times before, but I am building a ImageViewer with a UIScrollView and a UIPageControl. I am building it in Swift. Yet I have come across a issue which I can't seem to diagnose. I have a interesting setup to minimize long pages of code by splitting a view into containers. One for a tableview, the other for paging images. Here is a image of the storyboard. <a href="http://imgur.com/ZqvNgjy" rel="nofollow">http://imgur.com/ZqvNgjy</a> So in the first container view, it is a simple UIViewController with a UIScrollView and a UIPageControl. I can confirm that the UIPageControl is not in the view hierarchy of the UIScrollView. Now here is the code I used to setup everything.</p>
  
  <pre><code>import UIKit
  
  //Set Image Array
  var imagelist: String[] = ["Home Image 1.png", "info.png"]
  
  //Set Page Numbers
  var numpages = imagelist.count
  
  class HomeImageView: UIViewController, UIScrollViewDelegate {
  
      //IBOutlets &amp; Propertys
      @IBOutlet var scrollView: UIScrollView
  
      @IBOutlet var pageControl: UIPageControl
  
  
      override func viewDidLoad() {
  
          super.viewDidLoad()
  
          //Setup Page Control
          pageControl.numberOfPages = numpages
          pageControl.currentPage = 0
  
          //Setup Scroll View
          scrollView.pagingEnabled = true;
          scrollView.scrollEnabled = true
          scrollView.showsHorizontalScrollIndicator = false;
          scrollView.showsVerticalScrollIndicator = false;
          scrollView.bounces = true;
          scrollView.scrollsToTop = false
          scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * CGFloat(numpages), scrollView.frame.size.height)
  
  
          }
  
      override func viewWillAppear(animated: Bool) {
  
  
          //Setup UIViews with Images
          for var z = 0; z &lt; numpages; z++ {
  
              let mainFrame: CGRect = CGRectMake(scrollView.frame.size.width * CGFloat(z), 0, scrollView.frame.size.width, scrollView.frame.size.height)
  
              var image: UIImageView = UIImageView(frame: mainFrame)
  
              image.image = UIImage(named: imagelist[z])
  
              image.clipsToBounds = true
  
              image.contentMode = UIViewContentMode.ScaleAspectFit
  
              scrollView.addSubview(image)
  
      }
  
      func scrollViewDidScroll(scrollview: UIScrollView) {
  
          var pageSize: Float = Float(scrollView.bounds.size.width)
          var page: Float = floorf((Float(scrollview.contentOffset.x) - pageSize / 2.0) / pageSize) + 1
          // Bound page limits
          if (page &gt;= Float(numpages)) {
              page = Float(numpages) - 1;
          } else if (page &lt; 0) {
              page = 0;
          }
  
          pageControl.currentPage = Int(page)
          println(pageControl.currentPage)
      }
    }
  }
  </code></pre>
  
  <p>So with that out of the way, here is the problem. When I run it, it does not do exactly what I expected. The simulator starts like this <a href="http://imgur.com/RVlKxdf" rel="nofollow">http://imgur.com/RVlKxdf</a> and I can move the view around outside the bounds of the image.. Yet when I change the view hierarchy so that UIPageControl is behind the UIScrollView (Basically Removing it). The problem disappears completely. Aligned and allowing movement only in the bounds like I want. I don't know why the UIScrollView would react to the UIPageControl when it is outside its view hierarchy. Thanks for any assistance.</p>