         let doubleTap = UITapGestureRecognizer(target: self, action: #selector(didReceiveDoubleTap(_:)))
         doubleTap.numberOfTapsRequired = 2
         self.view.addGestureRecognizer(doubleTap)
+        
+        let pinch = UIPinchGestureRecognizer(target: self, action: #selector(didReceivePinch(_:)))
+        self.view.addGestureRecognizer(pinch)
     }
 
     override func didReceiveMemoryWarning() {

            scrollView.setZoomScale(1.0, animated: true)
        } else {
            let center = gesture.locationInView(imageView)
            let rectWidth = CGRectGetWidth(view.bounds) / scrollView.maximumZoomScale
            let rectHeight = CGRectGetHeight(view.bounds) / scrollView.maximumZoomScale
            let zoomRect = CGRectMake(center.x - rectWidth / 2, center.y - rectHeight / 2, rectWidth, rectHeight)
            scrollView.zoomToRect(zoomRect, animated: true)
        }
    }


        scrollView.contentSize = imageView.frame.size
        
        // Calculate the min scale factor and max scale factor
        scrollView.minimumZoomScale = 1.0
        scrollView.maximumZoomScale = 2.0
    }

    private func zoomToLocation(location : CGPoint, scale : CGFloat) {
        let rectWidth = CGRectGetWidth(view.bounds) / scale
        let rectHeight = CGRectGetHeight(view.bounds) / scale
        let zoomRect = CGRectMake(location.x - rectWidth / 2, location.y - rectHeight / 2, rectWidth, rectHeight)
        scrollView.zoomToRect(zoomRect, animated: true)
        
        let w = CGRectGetWidth(self.view.bounds)
        let h = CGRectGetHeight(self.view.bounds)
        scrollView.contentOffset = CGPointMake(w / 2 - rectWidth / 2, h / 2 - rectHeight / 2)
    }
    
    private func resetScrollView() {
        scrollView.contentOffset = CGPointZero
        scrollView.zoomScale = 1.0
    }
    
    private func pinchGestureDidChange(gesture : UIPinchGestureRecognizer) {
        // Limit the scale range
        var scale : CGFloat = gesture.scale
        scale = max(scale, scrollView.minimumZoomScale)
        scale = min(scale, scrollView.maximumZoomScale)
        let center = gesture.locationInView(scrollView)
        zoomToLocation(center, scale: scale)
    }
}
