From 4b7077fc5843f7781c1b7ba13b7cae2df161c409 Mon Sep 17 00:00:00 2001 From: Georg Kitz Date: Sun, 19 May 2013 21:07:24 +0200 Subject: [PATCH] fixes issue #21 this fixes the issue where a landscape croparea did work. thanks @ziweizhou for fixing this! --- GKClasses/GKImageCropView.m | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/GKClasses/GKImageCropView.m b/GKClasses/GKImageCropView.m index 2411928..11cea78 100644 --- a/GKClasses/GKImageCropView.m +++ b/GKClasses/GKImageCropView.m @@ -116,9 +116,19 @@ - (UIImage *)croppedImage{ //scaled width/height in regards of real width to crop width CGFloat scaleWidth = self.imageToCrop.size.width / self.cropSize.width; CGFloat scaleHeight = self.imageToCrop.size.height / self.cropSize.height; - CGFloat scale = MAX(scaleWidth, scaleHeight); + CGFloat scale = 0.0f; - //extract visible rect from scrollview and scale it + if (self.cropSize.width > self.cropSize.height) { + scale = (self.imageToCrop.size.width < self.imageToCrop.size.height ? + MAX(scaleWidth, scaleHeight) : + MIN(scaleWidth, scaleHeight)); + }else{ + scale = (self.imageToCrop.size.width < self.imageToCrop.size.height ? + MIN(scaleWidth, scaleHeight) : + MAX(scaleWidth, scaleHeight)); + } + + //extract visible rect from scrollview and scale it CGRect visibleRect = [scrollView convertRect:scrollView.bounds toView:imageView]; visibleRect = GKScaleRect(visibleRect, scale);