Fit the custom path
mrhaxic opened this issue · 1 comments
mrhaxic commented
Hello,
Thanks for the awesome library Am trying to make custom mask with the following path
CGFloat minX = (CGRectGetWidth(bounds)/2)/2, minY = (CGRectGetHeight(bounds)/2)/2, w = CGRectGetWidth(bounds)/2, h = CGRectGetHeight(bounds)/2;
[path2Path moveToPoint:CGPointMake(minX + 0.628 * w, minY + 0.94674 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.564 * w, minY + 0.98391 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.436 * w, minY + 0.98391 * h) controlPoint1:CGPointMake(minX + 0.526 * w, minY + 1.00536 * h) controlPoint2:CGPointMake(minX + 0.472 * w, minY + 1.00536 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.372 * w, minY + 0.94674 * h)];
[path2Path addCurveToPoint:CGPointMake(minX, minY + 0.37909 * h) controlPoint1:CGPointMake(minX + 0.136 * w, minY + 0.80947 * h) controlPoint2:CGPointMake(minX, minY + 0.60072 * h)];
[path2Path addLineToPoint:CGPointMake(minX, minY + 0.07024 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.102 * w, minY + 0.00018 * h) controlPoint1:CGPointMake(minX, minY + 0.02878 * h) controlPoint2:CGPointMake(minX + 0.048 * w, minY + -0.00268 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.168 * w, minY + 0.00447 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.832 * w, minY + 0.00447 * h) controlPoint1:CGPointMake(minX + 0.388 * w, minY + 0.01734 * h) controlPoint2:CGPointMake(minX + 0.61 * w, minY + 0.01734 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.898 * w, minY + 0.00018 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + w, minY + 0.07024 * h) controlPoint1:CGPointMake(minX + 0.952 * w, minY + -0.00268 * h) controlPoint2:CGPointMake(minX + w, minY + 0.02878 * h)];
[path2Path addLineToPoint:CGPointMake(minX + w, minY + 0.37909 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.628 * w, minY + 0.94674 * h) controlPoint1:CGPointMake(minX + w, minY + 0.60072 * h) controlPoint2:CGPointMake(minX + 0.864 * w, minY + 0.80947 * h)];
[path2Path closePath];
[path2Path moveToPoint:CGPointMake(minX + 0.628 * w, minY + 0.94674 * h)];
Where bounds is controller bounds.
But the question is how to fit the mask to be in the middle of controller.
Appreciated
ruslanskorb commented
#pragma mark - RSKImageCropViewControllerDataSource
- (UIBezierPath *)customMaskPathForBounds:(CGRect)bounds
{
UIBezierPath *path2Path = [[UIBezierPath alloc] init];
CGFloat minX = (CGRectGetWidth(bounds)/2)/2, minY = (CGRectGetHeight(bounds)/2)/2, w = CGRectGetWidth(bounds)/2, h = CGRectGetHeight(bounds)/2;
[path2Path moveToPoint:CGPointMake(minX + 0.628 * w, minY + 0.94674 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.564 * w, minY + 0.98391 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.436 * w, minY + 0.98391 * h) controlPoint1:CGPointMake(minX + 0.526 * w, minY + 1.00536 * h) controlPoint2:CGPointMake(minX + 0.472 * w, minY + 1.00536 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.372 * w, minY + 0.94674 * h)];
[path2Path addCurveToPoint:CGPointMake(minX, minY + 0.37909 * h) controlPoint1:CGPointMake(minX + 0.136 * w, minY + 0.80947 * h) controlPoint2:CGPointMake(minX, minY + 0.60072 * h)];
[path2Path addLineToPoint:CGPointMake(minX, minY + 0.07024 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.102 * w, minY + 0.00018 * h) controlPoint1:CGPointMake(minX, minY + 0.02878 * h) controlPoint2:CGPointMake(minX + 0.048 * w, minY + -0.00268 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.168 * w, minY + 0.00447 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.832 * w, minY + 0.00447 * h) controlPoint1:CGPointMake(minX + 0.388 * w, minY + 0.01734 * h) controlPoint2:CGPointMake(minX + 0.61 * w, minY + 0.01734 * h)];
[path2Path addLineToPoint:CGPointMake(minX + 0.898 * w, minY + 0.00018 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + w, minY + 0.07024 * h) controlPoint1:CGPointMake(minX + 0.952 * w, minY + -0.00268 * h) controlPoint2:CGPointMake(minX + w, minY + 0.02878 * h)];
[path2Path addLineToPoint:CGPointMake(minX + w, minY + 0.37909 * h)];
[path2Path addCurveToPoint:CGPointMake(minX + 0.628 * w, minY + 0.94674 * h) controlPoint1:CGPointMake(minX + w, minY + 0.60072 * h) controlPoint2:CGPointMake(minX + 0.864 * w, minY + 0.80947 * h)];
[path2Path closePath];
return path2Path;
}
- (UIBezierPath *)imageCropViewControllerCustomMaskPath:(RSKImageCropViewController *)controller
{
return [self customMaskPathForBounds:controller.view.bounds];
}
- (CGRect)imageCropViewControllerCustomMaskRect:(RSKImageCropViewController *)controller
{
return [self customMaskPathForBounds:controller.view.bounds].bounds;
}
- (CGRect)imageCropViewControllerCustomMovementRect:(RSKImageCropViewController *)controller
{
return controller.maskRect;
}
Please, in the future, ask such questions on Stackoverflow.