From 5ba5ed7f75ec0516acbee1eabc2e5dfd03e1979d Mon Sep 17 00:00:00 2001 From: Ruslan Skorb Date: Wed, 26 Sep 2018 06:15:10 +0300 Subject: [PATCH 1/3] [Sources] [RSKImageCropViewController] [croppedImage:cropMode:...] Center the mask instead of moving to the top-left. Fixes #200. --- RSKImageCropper/RSKImageCropViewController.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RSKImageCropper/RSKImageCropViewController.m b/RSKImageCropper/RSKImageCropViewController.m index b7a9c0c..8daf83d 100644 --- a/RSKImageCropper/RSKImageCropViewController.m +++ b/RSKImageCropper/RSKImageCropViewController.m @@ -963,9 +963,9 @@ - (UIImage *)croppedImage:(UIImage *)originalImage cropMode:(RSKImageCropMode)cr CGFloat scale = 1.0 / zoomScale; [maskPathCopy applyTransform:CGAffineTransformMakeScale(scale, scale)]; - // 5b: move the mask to the top-left. - CGPoint translation = CGPointMake(-CGRectGetMinX(maskPathCopy.bounds), - -CGRectGetMinY(maskPathCopy.bounds)); + // 5b: center the mask. + CGPoint translation = CGPointMake(-CGRectGetMinX(maskPathCopy.bounds) + (CGRectGetWidth(cropRect) - CGRectGetWidth(maskPathCopy.bounds)) * 0.5f, + -CGRectGetMinY(maskPathCopy.bounds) + (CGRectGetHeight(cropRect) - CGRectGetHeight(maskPathCopy.bounds)) * 0.5f); [maskPathCopy applyTransform:CGAffineTransformMakeTranslation(translation.x, translation.y)]; // 5c: apply the mask. From b8202ac1155ea5dfc776b1ef9af1ebdb33cb82af Mon Sep 17 00:00:00 2001 From: Ruslan Skorb Date: Wed, 26 Sep 2018 07:26:03 +0300 Subject: [PATCH 2/3] [Example] [Tests] [imageCropViewControllerCustomMovementRect:] Update `movementRect`. --- .../RSKImageCropViewControllerTests.m | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Example/RSKImageCropperExampleTests/RSKImageCropViewControllerTests.m b/Example/RSKImageCropperExampleTests/RSKImageCropViewControllerTests.m index 346245d..8e843a3 100644 --- a/Example/RSKImageCropperExampleTests/RSKImageCropViewControllerTests.m +++ b/Example/RSKImageCropperExampleTests/RSKImageCropViewControllerTests.m @@ -72,8 +72,26 @@ - (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewControl // Returns a custom rect in which the image can be moved. - (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller { - // If the image is not rotated, then the movement rect coincides with the mask rect. - return controller.maskRect; + if (controller.rotationAngle == 0) { + return controller.maskRect; + } else { + CGRect maskRect = controller.maskRect; + CGFloat rotationAngle = controller.rotationAngle; + + CGRect movementRect = CGRectZero; + + movementRect.size.width = CGRectGetWidth(maskRect) * fabs(cos(rotationAngle)) + CGRectGetHeight(maskRect) * fabs(sin(rotationAngle)); + movementRect.size.height = CGRectGetHeight(maskRect) * fabs(cos(rotationAngle)) + CGRectGetWidth(maskRect) * fabs(sin(rotationAngle)); + + movementRect.origin.x = CGRectGetMinX(maskRect) + (CGRectGetWidth(maskRect) - CGRectGetWidth(movementRect)) * 0.5f; + movementRect.origin.y = CGRectGetMinY(maskRect) + (CGRectGetHeight(maskRect) - CGRectGetHeight(movementRect)) * 0.5f; + + movementRect.origin.x = floor(CGRectGetMinX(movementRect)); + movementRect.origin.y = floor(CGRectGetMinY(movementRect)); + movementRect = CGRectIntegral(movementRect); + + return movementRect; + } } @end From f3bde5633c4be53daa89532a4c01a32f01a46449 Mon Sep 17 00:00:00 2001 From: Ruslan Skorb Date: Wed, 26 Sep 2018 07:27:38 +0300 Subject: [PATCH 3/3] Version bump (2.2.1). --- .../RSKImageCropperExample-Info.plist | 2 +- Framework/Info.plist | 2 +- RSKImageCropper.podspec | 2 +- RSKImageCropper.xcodeproj/project.pbxproj | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Example/RSKImageCropperExample/RSKImageCropperExample-Info.plist b/Example/RSKImageCropperExample/RSKImageCropperExample-Info.plist index 73b4523..18924f6 100755 --- a/Example/RSKImageCropperExample/RSKImageCropperExample-Info.plist +++ b/Example/RSKImageCropperExample/RSKImageCropperExample-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.2.0 + 2.2.1 CFBundleSignature ???? CFBundleVersion diff --git a/Framework/Info.plist b/Framework/Info.plist index a60ea4a..51c4067 100755 --- a/Framework/Info.plist +++ b/Framework/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.2.0 + 2.2.1 CFBundleSignature ???? CFBundleVersion diff --git a/RSKImageCropper.podspec b/RSKImageCropper.podspec index 3d4e356..8a15f25 100644 --- a/RSKImageCropper.podspec +++ b/RSKImageCropper.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'RSKImageCropper' - s.version = '2.2.0' + s.version = '2.2.1' s.summary = 'An image cropper for iOS like in the Contacts app with support for landscape orientation.' s.homepage = 'https://github.com/ruslanskorb/RSKImageCropper' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/RSKImageCropper.xcodeproj/project.pbxproj b/RSKImageCropper.xcodeproj/project.pbxproj index 64af49e..fb4cc32 100644 --- a/RSKImageCropper.xcodeproj/project.pbxproj +++ b/RSKImageCropper.xcodeproj/project.pbxproj @@ -236,7 +236,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2.2.0; + CURRENT_PROJECT_VERSION = 2.2.1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -294,7 +294,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 2.2.0; + CURRENT_PROJECT_VERSION = 2.2.1; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -321,8 +321,8 @@ buildSettings = { "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 2.2.0; - DYLIB_CURRENT_VERSION = 2.2.0; + DYLIB_COMPATIBILITY_VERSION = 2.2.1; + DYLIB_CURRENT_VERSION = 2.2.1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; @@ -339,8 +339,8 @@ buildSettings = { "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 2.2.0; - DYLIB_CURRENT_VERSION = 2.2.0; + DYLIB_COMPATIBILITY_VERSION = 2.2.1; + DYLIB_CURRENT_VERSION = 2.2.1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";