         }
         self.imageView.frame = contentsFrame
     }
+    //MARK:- Gesture Recognizer methods
+    func handleFlick(recognizer:UIPanGestureRecognizer) {
+        if isPresented && self.scrollView.zoomScale == self.scrollView.minimumZoomScale {
+            
+            if recognizer.state == UIGestureRecognizerState.Began {
+                
+            }
+            else if recognizer.state == UIGestureRecognizerState.Changed {
+                let translation = recognizer.translationInView(self.view)
+                if let view = recognizer.view {
+                    view.center = CGPoint(x:view.center.x + translation.x,
+                        y:view.center.y + translation.y)
+                }
+                recognizer.setTranslation(CGPointZero, inView: self.view)
+                
+            }
+            else if recognizer.state == UIGestureRecognizerState.Ended {
+                
+                
+                let velocity = recognizer.velocityInView(self.view)
+                let magnitude = sqrt((pow(velocity.x, 2.0) + pow(velocity.y, 2.0)))
+                if magnitude > FPLightBoxViewControllerConstants.dismissalFlickVelocityMagnitude {
+                    let push = UIPushBehavior(items: [self.imageView], mode: UIPushBehaviorMode.Instantaneous)
+                    push.pushDirection = CGVectorMake(velocity.x * 0.3, velocity.y * 0.3);
+                    self.animator.addBehavior(push)
+                    push.action = {
+                        if !CGRectIntersectsRect(self.view.frame, self.imageView.frame) {
+                            //print("Outside")
+                            UIView.animateWithDuration(1.0 , delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: {
+                                self.backgroundView.alpha = 0
+                                }, completion: {
+                                    (completed) in
+                                    self.dismissViewControllerAnimated(false, completion: {
+                                        (completed) in
+                                        print("Completed")
+                                    })
+                            })
+                        }
+                    }
+                }
+                else {
+                    UIView.animateWithDuration(0.2, delay: 0.0, options: .CurveLinear, animations: {
+                        () -> Void in
+                        self.imageView.center = self.view.center
+                        }, completion: nil)
+                }
+            }
+            
+        }
+    }
 }
            self.imageHeight = scale * (self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0)
            let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
            let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .ScaleAspectFill:
            let scale = max(widthRatio, heightRatio)
            self.imageWidth = scale * (self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0)
            self.imageHeight = scale * (self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0)
            let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
            let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .ScaleToFill:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            self.referenceFrame = self.referenceImageView.frame
        case .Top:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
            let imageY = self.referenceFrame.origin.y
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .Bottom:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = ((self.referenceFrame.size.width - self.imageWidth) / 2) + self.referenceFrame.origin.x
            let imageY = (self.referenceFrame.size.height + self.referenceFrame.origin.y) - self.imageHeight
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .Left:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = self.referenceFrame.origin.x
            let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .Right:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = (self.referenceFrame.origin.x + self.referenceFrame.size.width) - self.imageWidth
            let imageY = ((self.referenceFrame.size.height - self.imageHeight) / 2) + self.referenceFrame.origin.y
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .Center:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = self.referenceImageView.frame.origin.x + ((self.referenceImageView.frame.width - self.imageWidth) / 2)
            let imageY = self.referenceImageView.frame.origin.y + ((self.referenceImageView.frame.height - self.imageHeight) / 2)
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .TopLeft:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = self.referenceFrame.origin.x
            let imageY = self.referenceFrame.origin.y
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .TopRight:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = self.referenceFrame.origin.x + self.referenceFrame.size.width - self.imageWidth
            let imageY = self.referenceFrame.origin.y
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .BottomLeft:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = self.referenceFrame.origin.x
            let imageY = self.referenceFrame.origin.y + self.referenceFrame.size.height - self.imageHeight
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .BottomRight:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            let imageX = self.referenceFrame.origin.x + self.referenceFrame.size.width - self.imageWidth
            let imageY = self.referenceFrame.origin.y + self.referenceFrame.size.height - self.imageHeight
            self.referenceFrame = CGRectMake(imageX, imageY, self.imageWidth, self.imageHeight)
        case .Redraw:
            self.imageWidth = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.width : 0
            self.imageHeight = self.referenceImageView.image != nil ? self.referenceImageView.image!.size.height : 0
            self.referenceFrame = self.referenceImageView.frame
        }
        
    }
    func centerScrollViewContents() {

            if self.referenceImageView != nil {
                self.referenceFrame = self.referenceImageView.frame
                //Setting Reference frame
                self.referenceFrame = self.setReferenceFrameForMode(self.referenceImageView.contentMode)
                
                //Using the reference frame to set Up ImageView
                self.imageView = UIImageView(frame: self.referenceFrame)
                self.imageView.image = self.image
                //self.imageView.contentMode = .ScaleToFill
                self.imageView.contentMode = self.referenceImageView.contentMode
                self.imageView.clipsToBounds = false
                self.imageView.userInteractionEnabled = true
                self.imageView.layer.allowsEdgeAntialiasing = true
            }
            else {
                self.imageView = UIImageView(image: self.image)
