title: How to make the pageControl swipe effect? The scroll view slides continuously so far
body: <p>I would like to make the swipe effect with the scrollView, I found a project where nothing is specifically invoked in the code or in the storyboard. I repeated the code, but in my project, the scrollView just slides continuously, it does not swipe from one imageView to the other. Would you know how to do this?</p>
  
  <p>Here is the code, the scroll respond to the touch, the pagecontrol is a simple iboutlet, but there is no swipe effect (the scroll stops where the touch ends, instead of going back or moving the entire imageview ) :</p>
  
  <pre><code>class ViewController: UIViewController, UIScrollViewDelegate {
  
      @IBOutlet weak var pageControl: UIPageControl!
      @IBOutlet weak var scrollView: UIScrollView!
  
      var pageViews: [UIImageView?] = []
      var pageImages : [UIImage?] = []
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          pageImages = [UIImage(named:"photo1.png"),
          UIImage(named:"photo2.png"),
          UIImage(named:"photo3.png"),
          UIImage(named:"photo4.png")]
  
          let pageCount = pageImages.count
          pageControl.currentPage = 0
          pageControl.numberOfPages = pageCount
  
          for _ in 0..&lt;pageCount {
              pageViews.append(nil)
          }
  
          let pagesScrollViewSize = scrollView.frame.size
          println("pagesScrollViewSize : \(pagesScrollViewSize)")
          scrollView.contentSize = CGSizeMake(pagesScrollViewSize.width * CGFloat(pageCount), pagesScrollViewSize.height)
          loadVisiblePages()
      }
  
      //when scrolling
      func scrollViewDidScroll(scrollView: UIScrollView!){
          loadVisiblePages()
      }
  
      func loadVisiblePages(){
          let pageWidth = scrollView.frame.size.width
          let page = Int(floor( (scrollView.contentOffset.x * 2.0 + pageWidth) / (pageWidth*2.0) ))
          println("page: \(page)")
          pageControl.currentPage = page
          let firstPage = page-1
          let lastPage = page+1
          //remove all the pages before firstPage
          for var index = 0; index &lt; firstPage; ++index{
              purgePage(index)
          }
          //load pages in our range
          for var index = firstPage; index &lt;= lastPage; ++index {
              loadPage(index)
          }
          //remove after lastPage
          for var index = lastPage+1; index &lt; pageImages.count; ++index {
              purgePage(index)
          }
      }
  
      func loadPage(index:Int){
          if index &lt; 0 || index &gt;= pageImages.count {
              return
          }
          if let pageView = pageViews[index] {
              //already loaded
          }
          else {
              var frame = scrollView.bounds
              frame.origin.x = frame.size.width * CGFloat(index)
              frame.origin.y = 0.0
              println("\(frame)")
  
              var newImageView = UIImageView(image:pageImages[index])
              newImageView.contentMode = .ScaleAspectFit
              newImageView.frame = frame
              scrollView.addSubview(newImageView)
  
              pageViews[index] = newImageView
          }
      }
  
      func purgePage(index:Int){
          if index &lt; 0 || index &gt;= pageImages.count {
              return
          }
          if let pageView = pageViews[index] {
              pageView.removeFromSuperview()
              pageViews[index] = nil
          }
      }
  
  }
  </code></pre>