에 대한
UIImageView *maskedImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
UIBezierPath *nonagon = [UIBezierPath bezierPathWithPolygonInRect:maskedImageView.frame numberOfSides:6];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = nonagon.CGPath;
maskedImageView.layer.mask = shapeLayer;
[self.view addSubview:maskedImageView];
This is the library i used for the drawing the bezier path
감사합니다 아래 orm은 점 (0,0)을 중심으로 회전하고, 경로의 경우 점 (0,0)은 도형의 왼쪽 위 모서리입니다. 이것은 잘못된 점을 중심으로 회전하는 다른 작업을 수행하는 경우에만 90도 회전 할 때 오프셋이 올바르지 않은 이유입니다.
회전하기 전에 경로의 중심을 점 (0,0)으로 맞추고 회전 한 다음 (0,0)이 맨 위 왼쪽에 있도록 다시 이동해야합니다.
다음 코드는 폴리곤으로 90도 회전합니다
// get the size of the image, we'll need this for our path and for later too
CGRect boundsForPoly = maskedImageView.frame;
// create our path inside the rect
UIBezierPath *nonagon = [UIBezierPath bezierPathWithPolygonInRect:boundsForPoly numberOfSides:6];
// center the polygon on (0,0)
[nonagon applyTransform:CGAffineTransformMakeTranslation(-boundsForPoly.size.width/2, -boundsForPoly.size.height/2)];
// rotate it 90 degrees
[nonagon applyTransform:CGAffineTransformMakeRotation(M_PI/2)];
// now move it back so that the top left of its bounding box is (0,0)
[nonagon applyTransform:CGAffineTransformMakeTranslation(nonagon.bounds.size.width/2, nonagon.bounds.size.height/2)];
이 다각형으로 90도 회전되며, 파란색 개요는 (0,0)
에서이 왼쪽 상단의 유지 당신의 adam.wulf 전에서 대답에 문제가
180도 변환을에서 다음과 같이해야해야 하는가? 90을 원하지 않니? –
죄송합니다. 90도는 정확하지만 오프셋은 모두 정확하지 않으며 밑의 이미지는 보이지 않습니다. –