<commit_before>/**
 This class provides easy zooming for UIImageViews
 */
import UIKit
import Foundation
import ImageIO

public class EasyZoom: NSObject,UIScrollViewDelegate {
	
	//Instant imageView and ScrollView which will show your image and will make them zoom.
	var instantImageView:UIImageView?
	var instantScrollView:UIScrollView = UIScrollView()
	var instantImage:UIImage?
	var instantView:UIView?
	
	public var mainView = UIView()
	
	var doubleTapRecognizer:UITapGestureRecognizer
	var singleTapRecognizer:UITapGestureRecognizer
	var panGesture:UIPanGestureRecognizer
	var touchBack:UITapGestureRecognizer
	
	var didDoubleTapped:Bool = false
	
	public init(imageView:UIImageView, image:UIImage, superView: UIView) {
		instantView = superView
		instantImageView = imageView
		instantImageView?.userInteractionEnabled = true
		instantImage = image
		
		doubleTapRecognizer = UITapGestureRecognizer()
		singleTapRecognizer = UITapGestureRecognizer()
		panGesture = UIPanGestureRecognizer()
		touchBack = UITapGestureRecognizer()

		//scroll visible
		instantScrollView.showsHorizontalScrollIndicator = false
		instantScrollView.showsVerticalScrollIndicator = false

	}
	
	/**
		This public function adds zoom for imageViews.
	 @param imageView: UIImageView - The imageView where you can place zoom
	 @param image: UIImage - The image of imageView
	 @param superView: UIView - The superView which gonna cover zoomed imageView
	 */
	public func zoomForImageView() -> Void {
		
		//delegating of instant scrollView
		instantScrollView.delegate = self
		
		instantImage = cropTheImage(instantImage!, i_width: instantView!.frame.size.width, i_height: instantView!.frame.size.height)
		
		//setting instant scrollView frame to user imageView
		instantScrollView.frame = instantView!.frame
//		instantImageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: instantImage.size)

		//setting constraints
		instantScrollView.contentSize = instantImage!.size
		setTheConstraints(instantImageView!, superView: instantScrollView, hConstraints: "|-[subview]", vConstraints: "|-[subview]")
		setTheConstraints(instantScrollView, superView: instantView!, hConstraints: "|-[subview]-|", vConstraints: "|-[subview]-|")
		instantImageView!.contentMode = .ScaleAspectFit
		instantImageView!.image = instantImage
		
		//setting tap gesture recognizer
		doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "didDoubleTapped:")
		doubleTapRecognizer.numberOfTapsRequired = 2
		doubleTapRecognizer.numberOfTouchesRequired = 1
		instantImageView!.addGestureRecognizer(doubleTapRecognizer)
		//didDoubleTapped = true
		
		//setting minumum and maximum zoom scale
		setTheZoomScale()
		
		//centerizing content
		centerizeContent(instantScrollView, imageView: instantImageView!)
		
		//adding tap gesture recognizer
		singleTouchToNewView()
	}
	
	
	/**
	This function makes image view to return its default view format.
	*/
	func returnDefaultState() {
		
		instantImage = cropTheImage(instantImage!, i_width: instantView!.frame.size.width, i_height: instantView!.frame.size.height)
		
//		//setting instant scrollView frame to user imageView
		instantScrollView.frame = instantView!.frame
		instantImageView!.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: instantImage!.size)

//		//setting constraints
		instantScrollView.contentSize = instantImage!.size
		setTheConstraints(instantImageView!, superView: instantScrollView, hConstraints: "|-[subview]", vConstraints: "|-[subview]")
		instantImageView!.contentMode = .ScaleAspectFit

//		//centerizing content
		centerizeContent(instantScrollView, imageView: instantImageView!)
		
	}
	
	func setTheZoomScale() {
		
		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 = 10.0
		instantScrollView.zoomScale = minScale
		
	}
	
	func setTheConstraints(subview:UIView, superView:UIView,hConstraints:String,vConstraints:String) {
		let views:Dictionary = ["subview":subview]
		let imageViewSize = instantScrollView.frame.size
		let imageViewSizesMetric = ["height":imageViewSize.height,"width":imageViewSize.width]
		subview.setTranslatesAutoresizingMaskIntoConstraints(false)
		superView.addSubview(subview)
		let vCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("V:\(vConstraints)", options: NSLayoutFormatOptions(0), metrics: imageViewSizesMetric, views: views)
		let hCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("H:\(hConstraints)", options: NSLayoutFormatOptions(0), metrics: imageViewSizesMetric, views: views)
		superView.addConstraints(vCons)
		superView.addConstraints(hCons)
	}
	
	/**
		This is for single tap tap to new view which has same features with the normal one
	*/
	public func singleTouchToNewView() {
		singleTapRecognizer = UITapGestureRecognizer(target: self, action: "singleTouchHandler")
		singleTapRecognizer.requireGestureRecognizerToFail(doubleTapRecognizer)

		instantScrollView.addGestureRecognizer(singleTapRecognizer)
	}
	
	func singleTouchHandler() {
		let screenSize:CGRect = UIScreen.mainScreen().bounds.standardizedRect
		var fullSizeView = UIView(frame: screenSize)
		//setting constraints of new full size view
		self.setTheConstraints(fullSizeView, superView: mainView, hConstraints: "|-0-[subview]-0-|", vConstraints: "|-0-[subview]-0-|")
		self.setTheConstraints(instantScrollView, superView: fullSizeView, hConstraints: "|-[subview]-|", vConstraints: "|-[subview]-|")
		self.setTheConstraints(instantImageView!, superView: instantScrollView, hConstraints: "|-[subview]", vConstraints: "|-[subview]")
		
		instantScrollView.setNeedsLayout()
		instantScrollView.setNeedsDisplay()
		
		//adding pan recognizer
		panGesture = UIPanGestureRecognizer(target: self, action: "panToFullScreen:")
		touchBack = UITapGestureRecognizer(target: self, action: "touchBackHandler:")
		instantScrollView.addGestureRecognizer(panGesture)
		instantScrollView.addGestureRecognizer(touchBack)
	}
	
	/**
	Pan gesture recognizer selector function.
	@param recognizer - UIPanGestureRecognizer
	*/<commit_msg>Touch back and double tap gestures failing fixed<commit_after>/**
 This class provides easy zooming for UIImageViews
 */
import UIKit
import Foundation
import ImageIO

public class EasyZoom: NSObject,UIScrollViewDelegate {
	
	//Instant imageView and ScrollView which will show your image and will make them zoom.
	var instantImageView:UIImageView?
	var instantScrollView:UIScrollView = UIScrollView()
	var instantImage:UIImage?
	var instantView:UIView?
	
	public var mainView = UIView()
	
	var doubleTapRecognizer:UITapGestureRecognizer
	var singleTapRecognizer:UITapGestureRecognizer
	var panGesture:UIPanGestureRecognizer
	var touchBack:UITapGestureRecognizer
	
	var didDoubleTapped:Bool = false
	
	public init(imageView:UIImageView, image:UIImage, superView: UIView) {
		instantView = superView
		instantImageView = imageView
		instantImageView?.userInteractionEnabled = true
		instantImage = image
		
		doubleTapRecognizer = UITapGestureRecognizer()
		singleTapRecognizer = UITapGestureRecognizer()
		panGesture = UIPanGestureRecognizer()
		touchBack = UITapGestureRecognizer()

		//scroll visible
		instantScrollView.showsHorizontalScrollIndicator = false
		instantScrollView.showsVerticalScrollIndicator = false

	}
	
	/**
		This public function adds zoom for imageViews.
	 @param imageView: UIImageView - The imageView where you can place zoom
	 @param image: UIImage - The image of imageView
	 @param superView: UIView - The superView which gonna cover zoomed imageView
	 */
	public func zoomForImageView() -> Void {
		
		//delegating of instant scrollView
		instantScrollView.delegate = self
		
		instantImage = cropTheImage(instantImage!, i_width: instantView!.frame.size.width, i_height: instantView!.frame.size.height)
		
		//setting instant scrollView frame to user imageView
		instantScrollView.frame = instantView!.frame
//		instantImageView.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: instantImage.size)

		//setting constraints
		instantScrollView.contentSize = instantImage!.size
		setTheConstraints(instantImageView!, superView: instantScrollView, hConstraints: "|-[subview]", vConstraints: "|-[subview]")
		setTheConstraints(instantScrollView, superView: instantView!, hConstraints: "|-[subview]-|", vConstraints: "|-[subview]-|")
		instantImageView!.contentMode = .ScaleAspectFit
		instantImageView!.image = instantImage
		
		//setting tap gesture recognizer
		doubleTapRecognizer = UITapGestureRecognizer(target: self, action: "didDoubleTapped:")
		doubleTapRecognizer.numberOfTapsRequired = 2
		doubleTapRecognizer.numberOfTouchesRequired = 1
		instantImageView!.addGestureRecognizer(doubleTapRecognizer)
		//didDoubleTapped = true
		
		//setting minumum and maximum zoom scale
		setTheZoomScale()
		
		//centerizing content
		centerizeContent(instantScrollView, imageView: instantImageView!)
		
		//adding tap gesture recognizer
		singleTouchToNewView()
	}
	
	
	/**
	This function makes image view to return its default view format.
	*/
	func returnDefaultState() {
		
		instantImage = cropTheImage(instantImage!, i_width: instantView!.frame.size.width, i_height: instantView!.frame.size.height)
		
//		//setting instant scrollView frame to user imageView
		instantScrollView.frame = instantView!.frame
		instantImageView!.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: instantImage!.size)

//		//setting constraints
		instantScrollView.contentSize = instantImage!.size
		setTheConstraints(instantImageView!, superView: instantScrollView, hConstraints: "|-[subview]", vConstraints: "|-[subview]")
		instantImageView!.contentMode = .ScaleAspectFit

//		//centerizing content
		centerizeContent(instantScrollView, imageView: instantImageView!)
		
	}
	
	func setTheZoomScale() {
		
		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 = 10.0
		instantScrollView.zoomScale = minScale
		
	}
	
	func setTheConstraints(subview:UIView, superView:UIView,hConstraints:String,vConstraints:String) {
		let views:Dictionary = ["subview":subview]
		let imageViewSize = instantScrollView.frame.size
		let imageViewSizesMetric = ["height":imageViewSize.height,"width":imageViewSize.width]
		subview.setTranslatesAutoresizingMaskIntoConstraints(false)
		superView.addSubview(subview)
		let vCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("V:\(vConstraints)", options: NSLayoutFormatOptions(0), metrics: imageViewSizesMetric, views: views)
		let hCons:Array = NSLayoutConstraint.constraintsWithVisualFormat("H:\(hConstraints)", options: NSLayoutFormatOptions(0), metrics: imageViewSizesMetric, views: views)
		superView.addConstraints(vCons)
		superView.addConstraints(hCons)
	}
	
	/**
		This is for single tap tap to new view which has same features with the normal one
	*/
	public func singleTouchToNewView() {
		singleTapRecognizer = UITapGestureRecognizer(target: self, action: "singleTouchHandler")
		singleTapRecognizer.requireGestureRecognizerToFail(doubleTapRecognizer)

		instantScrollView.addGestureRecognizer(singleTapRecognizer)
	}
	
	func singleTouchHandler() {
		let screenSize:CGRect = UIScreen.mainScreen().bounds.standardizedRect
		var fullSizeView = UIView(frame: screenSize)
		//setting constraints of new full size view
		self.setTheConstraints(fullSizeView, superView: mainView, hConstraints: "|-0-[subview]-0-|", vConstraints: "|-0-[subview]-0-|")
		self.setTheConstraints(instantScrollView, superView: fullSizeView, hConstraints: "|-[subview]-|", vConstraints: "|-[subview]-|")
		self.setTheConstraints(instantImageView!, superView: instantScrollView, hConstraints: "|-[subview]", vConstraints: "|-[subview]")
		
		instantScrollView.setNeedsLayout()
		instantScrollView.setNeedsDisplay()
		
		//adding pan recognizer
		panGesture = UIPanGestureRecognizer(target: self, action: "panToFullScreen:")
		touchBack = UITapGestureRecognizer(target: self, action: "touchBackHandler:")
		instantScrollView.addGestureRecognizer(panGesture)
		instantScrollView.addGestureRecognizer(touchBack)
		
		touchBack.requireGestureRecognizerToFail(doubleTapRecognizer)
	}
	
	/**
	Pan gesture recognizer selector function.
	@param recognizer - UIPanGestureRecognizer
	*/
{'fraction_non_alphanumeric': 0.09201826196473552, 'fraction_numerical': 0.0023614609571788415, 'mean_word_length': 5.834319526627219, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4119811', 'n_tokens_mistral': 4261, 'n_tokens_neox': 3606, 'n_words': 820}