Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rectangle mode avoidEmptySpaceAroundImage not working #38

Closed
dyadenkor opened this issue Mar 13, 2015 · 7 comments
Closed

Rectangle mode avoidEmptySpaceAroundImage not working #38

dyadenkor opened this issue Mar 13, 2015 · 7 comments

Comments

@dyadenkor
Copy link

Hi gents, I've tried rectangle mode (for quick testing I've used square mode, but change this in source code CGSize maskSize = CGSizeMake(length, length * 0.75));

And here the result https://www.dropbox.com/s/lp2yuhx0lnzoubu/Screenshot%202015-03-13%2018.05.19.png?dl=0

avoidEmptySpaceAroundImage not working with rectangle mode for me, but perfect with square.

Or how should I create rectangle mode then? Thanks.

@ruslanskorb
Copy link
Owner

Hi @dyadenkor,

Rectangle mode is the custom mode.
You need to set cropMode to RSKImageCropModeCustom and implement data source methods.

To support the rotation when cropMode is RSKImageCropModeCustom you must implement the data source method imageCropViewControllerCustomMovementRect:.

Then avoidEmptySpaceAroundImage will work properly.

@dyadenkor
Copy link
Author

Thanks, will try and will tell you the result. Thanks!

@dyadenkor
Copy link
Author

I'he tried. https://www.dropbox.com/s/laralbs0d0fewjm/Screenshot%202015-03-13%2021.33.15.png?dl=0

What I am doing wrong?

#pragma mark - Action handling

  • (void)onAddPhotoButtonTouch:(UIButton *)sender
    {
    UIImage *photo = [UIImage imageNamed:@"photo"];
    RSKImageCropViewController *imageCropVC = [[RSKImageCropViewController alloc] initWithImage:photo cropMode:RSKImageCropModeCustom];
    imageCropVC.avoidEmptySpaceAroundImage = YES;
    imageCropVC.rotationEnabled = YES;
    imageCropVC.dataSource = self;
    imageCropVC.delegate = self;
    [self.navigationController pushViewController:imageCropVC animated:YES];
    }

#pragma mark - RSKImageCropViewControllerDataSource

// Returns a custom rect for the mask.

  • (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller
    {
    CGFloat viewWidth = CGRectGetWidth(self.view.frame);
    CGFloat viewHeight = CGRectGetHeight(self.view.frame);

    CGRect maskRect = CGRectMake(0,
    (viewHeight - viewWidth) * 0.25f,
    viewWidth,
    viewWidth * 0.75f);

    return maskRect;
    }

// Returns a custom path for the mask.

  • (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller
    {
    CGRect rect = controller.maskRect;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRect:rect];
    return maskPath;
    }

// Returns a custom rect in which the image can be moved.

  • (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller
    {
    return [self imageCropViewControllerCustomMaskRect:controller];
    }

@ruslanskorb
Copy link
Owner

You should calculate and return the correct movement rect according to the current values of the parameters, such as the angle of rotation.
It's a usage question. You can ask about it on stack overflow.

@pronebird
Copy link
Contributor

We should include rotation in sample app, I think not many understand what movement rect is.

@dyadenkor
Copy link
Author

I understand what is this, but I can't understand how could I calculate it. I saw many calculations in sources, could you explain, please in words these processes. Thanks :)

@ruslanskorb
Copy link
Owner

@dyadenkor, you can read about these processes here

@pronebird, what kind of example would you add?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants