Skip to content

Commit

Permalink
[Example + README + Sources] [RSKImageCropViewControllerDelegate] Rem…
Browse files Browse the repository at this point in the history
…ove `imageCropViewController:didCropImage:usingCropRect:` method.
  • Loading branch information
ruslanskorb committed Nov 29, 2017
1 parent 0e32697 commit c088cce
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Example/RSKImageCropperExample/RSKExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ - (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)contr
[self.navigationController popViewControllerAnimated:YES];
}

- (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect
- (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect rotationAngle:(CGFloat)rotationAngle
{
[self.addPhotoButton setImage:croppedImage forState:UIControlStateNormal];
[self.navigationController popViewControllerAnimated:YES];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,11 @@ @interface RSKImageCropViewControllerDelegateObject1 : NSObject <RSKImageCropVie
@implementation RSKImageCropViewControllerDelegateObject1

- (void)imageCropViewController:(RSKImageCropViewController *)controller willCropImage:(UIImage *)originalImage {}
- (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect {};
- (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect rotationAngle:(CGFloat)rotationAngle {};
- (void)imageCropViewControllerDidCancelCrop:(RSKImageCropViewController *)controller {};

@end

@interface RSKImageCropViewControllerDelegateObject2 : NSObject <RSKImageCropViewControllerDelegate>

@end

@implementation RSKImageCropViewControllerDelegateObject2

- (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect rotationAngle:(CGFloat)rotationAngle {}

@end

static const CGFloat kLayoutImageScrollViewAnimationDuration = 0.25;

@interface RSKImageCropViewController (Testing)
Expand Down Expand Up @@ -696,20 +686,6 @@ - (void)resetZoomScale;
id delegateMock = [OCMockObject partialMockForObject:delegateObject];

[[delegateMock expect] imageCropViewController:imageCropViewController willCropImage:OCMOCK_ANY];
[[delegateMock expect] imageCropViewController:imageCropViewController didCropImage:OCMOCK_ANY usingCropRect:imageCropViewController.cropRect];

[imageCropViewController cropImage];

[delegateMock verifyWithDelay:1.0];
[delegateMock stopMocking];
});

it(@"calls the appropriate delegate method after cropping image", ^{
RSKImageCropViewControllerDelegateObject2 *delegateObject = [[RSKImageCropViewControllerDelegateObject2 alloc] init];
imageCropViewController.delegate = delegateObject;

id delegateMock = [OCMockObject partialMockForObject:delegateObject];

[[delegateMock expect] imageCropViewController:imageCropViewController didCropImage:OCMOCK_ANY usingCropRect:imageCropViewController.cropRect rotationAngle:imageCropViewController.rotationAngle];

[imageCropViewController cropImage];
Expand Down
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Just create a view controller for image cropping and set the delegate.

## Delegate

`RSKImageCropViewControllerDelegate` provides four delegate methods. To use them, implement the delegate in your view controller.
`RSKImageCropViewControllerDelegate` provides three delegate methods. To use them, implement the delegate in your view controller.

```objective-c
@interface ViewController () <RSKImageCropViewControllerDelegate>
Expand All @@ -66,15 +66,6 @@ Then implement the delegate functions.
[self.navigationController popViewControllerAnimated:YES];
}
// The original image has been cropped.
- (void)imageCropViewController:(RSKImageCropViewController *)controller
didCropImage:(UIImage *)croppedImage
usingCropRect:(CGRect)cropRect
{
self.imageView.image = croppedImage;
[self.navigationController popViewControllerAnimated:YES];
}
// The original image has been cropped. Additionally provides a rotation angle used to produce image.
- (void)imageCropViewController:(RSKImageCropViewController *)controller
didCropImage:(UIImage *)croppedImage
Expand Down Expand Up @@ -146,7 +137,8 @@ Then implement the data source functions.
// 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.
// If the image is not rotated, then the movement rect coincides with the mask rect,
// otherwise it is calculated individually for each custom mask.
return controller.maskRect;
}
```
Expand Down
4 changes: 0 additions & 4 deletions RSKImageCropper/RSKImageCropViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,6 @@ typedef NS_ENUM(NSUInteger, RSKImageCropMode) {
*/
- (void)imageCropViewController:(RSKImageCropViewController *)controller willCropImage:(UIImage *)originalImage;

/**
Tells the delegate that the original image has been cropped. Additionally provides a crop rect used to produce image.
*/
- (void)imageCropViewController:(RSKImageCropViewController *)controller didCropImage:(UIImage *)croppedImage usingCropRect:(CGRect)cropRect;

/**
Tells the delegate that the original image has been cropped. Additionally provides a crop rect and a rotation angle used to produce image.
Expand Down
6 changes: 1 addition & 5 deletions RSKImageCropper/RSKImageCropViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,7 @@ - (void)cropImage
UIImage *croppedImage = [self croppedImage:originalImage cropMode:cropMode cropRect:cropRect rotationAngle:rotationAngle zoomScale:zoomScale maskPath:maskPath applyMaskToCroppedImage:applyMaskToCroppedImage];

dispatch_async(dispatch_get_main_queue(), ^{
if ([self.delegate respondsToSelector:@selector(imageCropViewController:didCropImage:usingCropRect:rotationAngle:)]) {
[self.delegate imageCropViewController:self didCropImage:croppedImage usingCropRect:cropRect rotationAngle:rotationAngle];
} else if ([self.delegate respondsToSelector:@selector(imageCropViewController:didCropImage:usingCropRect:)]) {
[self.delegate imageCropViewController:self didCropImage:croppedImage usingCropRect:cropRect];
}
[self.delegate imageCropViewController:self didCropImage:croppedImage usingCropRect:cropRect rotationAngle:rotationAngle];
});
});
}
Expand Down

0 comments on commit c088cce

Please sign in to comment.