         if self.delegate!.respondsToSelector("photoSliderControllerWillDismiss:") {
             self.delegate!.photoSliderControllerWillDismiss!(self)
         }
-        self.dismissViewController()
+        self.dissmissViewControllerAnimated(true)
     }
     
     // MARK: - Private Methods
     
-    func dismissViewController() {
-        self.dismissViewControllerAnimated(true, completion: { () -> Void in
+    func dissmissViewControllerAnimated(animated:Bool) {
+        self.dismissViewControllerAnimated(animated, completion: { () -> Void in
             
             if self.delegate!.respondsToSelector("photoSliderControllerDidDismiss:") {
                 self.delegate!.photoSliderControllerDidDismiss!(self)

                    self.view.alpha = 0.0
                },
                completion: {(result) -> Void in
                    self.dismissViewController()
                }
            )
            
            return
        }

        var offsetX = fabs(scrollView.contentOffset.x - self.scrollPreviewPoint.x)
        var offsetY = fabs(scrollView.contentOffset.y - self.scrollPreviewPoint.y)
        if offsetY > offsetX {
            var contentOffset = scrollView.contentOffset
            contentOffset.x = self.scrollPreviewPoint.x
            scrollView.contentOffset = contentOffset
            
            let alpha:CGFloat = 1.0 - (scrollView.contentOffset.y * 2.0 / scrollView.frame.size.height / 2.0)
            self.backgroundView.alpha = alpha
        } else {
            var contentOffset = scrollView.contentOffset
            contentOffset.y = self.scrollPreviewPoint.y
            scrollView.contentOffset = contentOffset
        }

        // paging
        if visiblePageControl {
            if fmod(scrollView.contentOffset.x, scrollView.frame.size.width) == 0.0 {
                self.pageControl.currentPage = Int(scrollView.contentOffset.x / scrollView.frame.size.width)
            }
        }
        
    }

    // MARK: - Button Actions

    optional func photoSliderControllerWillDismiss(viewController: PhotoSlider.ViewController)
    optional func photoSliderControllerDidDismiss(viewController: PhotoSlider.ViewController)
}

enum PhotoSliderControllerScrollMode:Int {
    case None = 0, Vertical, Horizontal
}



public class ViewController:UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
