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

Image not moving in vertical mode after rotate. #179

Closed
dineshmahajan opened this issue Nov 3, 2017 · 13 comments
Closed

Image not moving in vertical mode after rotate. #179

dineshmahajan opened this issue Nov 3, 2017 · 13 comments
Labels

Comments

@dineshmahajan
Copy link

When I rotate image with 90 degree then not able to move image top & down, please check & let me know solution for it.

@ruslanskorb
Copy link
Owner

@dineshmahajan Can you provide a sample project?

@dineshmahajan
Copy link
Author

Please check attach video file Frame is not updates after rotate
Video.zip

@ruslanskorb
Copy link
Owner

@dineshmahajan I noticed that you are using a custom crop mode.
Can you, please, provide your implementation of RSKImageCropViewControllerDataSource methods?

@dineshmahajan
Copy link
Author

Class.zip
Hi Thanks for quick response, Please download my file & replace RSKExampleViewController class in an example provided on git.

Thanks

@ruslanskorb
Copy link
Owner

@dineshmahajan

If you want to support the rotation when cropMode is RSKImageCropModeCustom you must implement the method imageCropViewControllerCustomMovementRect:.

If the image is not rotated, then the movement rect coincides with the mask rect. In other cases you need to calculate and return the correct value from imageCropViewControllerCustomMovementRect:.

You can see how it is done for the square here.

@dineshmahajan
Copy link
Author

dineshmahajan commented Nov 5, 2017 via email

@ruslanskorb
Copy link
Owner

It is impossible to calculate a movement rect for an unknown mask rect. Therefore, it is the responsibility of the developer who uses this library.

@dineshmahajan
Copy link
Author

dineshmahajan commented Nov 5, 2017 via email

@ruslanskorb
Copy link
Owner

You can see how to calculate a movement rect for the square here. I hope it will guide you in the right direction.

@dineshmahajan
Copy link
Author

dineshmahajan commented Nov 5, 2017 via email

@rursache
Copy link

rursache commented May 29, 2018

@ruslanskorb i also needed this implementation so maybe you can add the following code i used in the readme file:

add this to your Utils class or VC

Swift:

func getBoundingRectAfterRotation(rect: CGRect, angle: Float) -> CGRect {
    let newWidth = Float(rect.size.width) * abs(cosf(angle)) + Float(rect.size.height) * fabs(sinf(angle))
    let newHeight = Float(rect.size.height) * fabs(cosf(angle)) + Float(rect.size.width) * fabs(sinf(angle))
    
    let newX = Float(rect.origin.x) + ((Float(rect.size.width) - newWidth) / 2);
    let newY = Float(rect.origin.y) + ((Float(rect.size.height) - newHeight) / 2);
    
    let rotatedRect = CGRect(x: CGFloat(newX), y: CGFloat(newY), width: CGFloat(newWidth), height: CGFloat(newHeight))
    
    return rotatedRect
}

Objective-C:

- (CGRect)getBoundingRectAfterRotation:(CGRect)rect angle:(float)angle {
    
    CGFloat newWidth = (float)(rect.size.width) * fabs(cosf(angle)) + (float)(rect.size.height) * fabs(sinf(angle));
    CGFloat newHeight = (float)(rect.size.height) * fabs(cosf(angle)) + (float)(rect.size.width) * fabs(sinf(angle));
    
    CGFloat newX = (float)(rect.origin.x) + (((float)(rect.size.width) - newWidth) / 2);
    CGFloat newY = (float)(rect.origin.y) + (((float)(rect.size.height) - newHeight) / 2);
    
    CGRect rotatedRect = CGRectMake((float)(newX), (float)(newY), (float)(newWidth), (float)(newHeight));
    
    return rotatedRect;
}

then implement RSKImageCropViewControllerDataSource and add:

func imageCropViewControllerCustomMovementRect(_ controller: RSKImageCropViewController) -> CGRect {
    return self.getBoundingRectAfterRotation(rect: controller.maskRect, angle: Float(controller.rotationAngle))
}

thank you for this great library!

@ruslanskorb
Copy link
Owner

@iphonewsro Thanks! I'm thinking of adding a new mode RSKImageCropModeRectangle. This can be useful for this case.

@ruslanskorb
Copy link
Owner

Added working example to README.

ruslanskorb added a commit that referenced this issue Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants