  */
 import UIKit
 import Foundation
+import ImageIO
 
 public class EasyZoom: NSObject,UIScrollViewDelegate {
 	

		//delegating of instant scrollView
		instantScrollView.delegate = self
		
		
		//setting instant scrollView frame to user imageView
		instantScrollView.frame = instantView.frame
		instantImageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: instantImage.size)

		//setting zoom area
		instantScrollView.contentSize = instantImage.size
		
		let viewsDictionary = ["imageView":instantImageView,"scrollView":instantScrollView]
		instantScrollView.setTranslatesAutoresizingMaskIntoConstraints(false)
		instantImageView.setTranslatesAutoresizingMaskIntoConstraints(false)
		
		instantImageView.image = instantImage
		
		instantScrollView.addSubview(instantImageView)
		instantView.addSubview(instantScrollView)

		//scrollview constraints
		
		let scrollHCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[scrollView]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDictionary)
		let scrollVCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("V:|-[scrollView]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: viewsDictionary)
		instantView.addConstraints(scrollHCons)
		instantView.addConstraints(scrollVCons)
		
		instantScrollView.setNeedsLayout()
		instantScrollView.setNeedsDisplay()
		
		//imageView constraints
		
		let imageViewSize = instantScrollView.frame.size
		let imageViewSizesMetric = ["height":imageViewSize.height,"width":imageViewSize.width]
		let imageViewVCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("V:|-[imageView]", options: NSLayoutFormatOptions(0), metrics: imageViewSizesMetric, views: viewsDictionary)
		let imageViewHCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[imageView(width)]", options: NSLayoutFormatOptions(0), metrics: imageViewSizesMetric, views: viewsDictionary)
		instantScrollView.addConstraints(imageViewHCons)
		instantScrollView.addConstraints(imageViewVCons)

		//fixes image size
		instantImageView.contentMode = UIViewContentMode.ScaleAspectFill
		
		//setting tap gesture recognizer
		doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "didDoubleTapped:")
		doubleTapRecognizer.numberOfTapsRequired = 2
		doubleTapRecognizer.numberOfTouchesRequired = 1
		instantScrollView.addGestureRecognizer(doubleTapRecognizer)
		didDoubleTapped = true
		
		//setting minumum and maximum zoom scale
		let scrollViewFrame = instantScrollView.frame
		let scaleWidth = scrollViewFrame.size.width / instantScrollView.contentSize.width
		let scaleHeight = scrollViewFrame.size.height / instantScrollView.contentSize.height
		let minScale = min(scaleWidth, scaleHeight)
		instantScrollView.minimumZoomScale = minScale
		
		instantScrollView.maximumZoomScale = 1.0
		instantScrollView.zoomScale = minScale
		
		//centerizing content
		centerizeContent(instantScrollView, imageView: instantImageView)
	}
	/**
		This is for single tap tap to new view which has same features with the normal one
	*/
	public func singleTouchToNewView() {
		let singleTapRecognizer:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "singleTouchHandler")
		singleTapRecognizer.requireGestureRecognizerToFail(doubleTapRecognizer)
		instantScrollView.addGestureRecognizer(singleTapRecognizer)
		
		var panGesture = UIPanGestureRecognizer(target: self, action: "handlePan:")
		instantScrollView.addGestureRecognizer(panGesture)
	}
	
	func singleTouchHandler() {
		let screenSize:CGRect = UIScreen.mainScreen().bounds
		var fullSizeView = UIView(frame: screenSize)
		fullSizeView.backgroundColor = UIColor.blueColor()
		mainView.addSubview(fullSizeView)
		fullSizeView.addSubview(instantView)
	}
	
	
	func panToFullScreenView() {
		let panToFullScreenRecognizer = UIPanGestureRecognizer(target: self, action: "panToFullScreen:")
		instantScrollView.addGestureRecognizer(panToFullScreenRecognizer)
	}
	
	func panToFullScreen(recognizer:UIPanGestureRecognizer) {
		let constantFrame:CGRect = instantImageView.frame
		let translation = recognizer.translationInView(instantView)
		if let view = recognizer.view {
			view.center = CGPoint(x: view.center.x + translation.x , y: view.center.y + translation.y)
			if (view.center.y + instantImageView.bounds.midY > instantView.bounds.midY) {
				instantView.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.5)
				instantScrollView.zoomScale = 0
			}
		}
		recognizer.setTranslation(CGPointZero, inView: instantView)
	}
	
	/**

	public var mainView = UIView()
	
	var doubleTapRecognizer:UITapGestureRecognizer
	var singleTapRecognizer:UITapGestureRecognizer
	
	var didDoubleTapped = Bool()
	
	public init(imageView:UIImageView, image:UIImage, superView: UIView) {
		instantView = superView
		instantImageView = imageView
		instantImageView.userInteractionEnabled = true
		instantImage = image
		
		doubleTapRecognizer = UITapGestureRecognizer()
		singleTapRecognizer = UITapGestureRecognizer()
		//scroll visible
		instantScrollView.showsHorizontalScrollIndicator = false
		instantScrollView.showsVerticalScrollIndicator = false
	}
	
	/**
