旋转 CAShapeLayer
Rotate CAShapeLayer
我正在尝试原地旋转 CAShapeLayer
UIBezierPath *aPath = [UIBezierPath bezierPath];
CGFloat originx = (97.5+250);
CGFloat originy = (205+250);
[aPath moveToPoint:CGPointMake(originx,originy)];
[aPath addArcWithCenter:CGPointMake(originx+15, originy-30) radius:15 startAngle:DEGREES_TO_RADIANS(180) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
[aPath addLineToPoint:CGPointMake(originx+30,originy)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.anchorPoint = CGPointMake(originx, originy);
shapeLayer.path = [aPath CGPath];
shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
shapeLayer.lineWidth = 3.0;
shapeLayer.fillColor = [[UIColor blueColor] CGColor];
[aPath closePath];
shapeLayer.transform = CATransform3DMakeRotation(310 * M_PI/180, 0.0, 0.0, 1.0);
[self.view.layer addSublayer:shapeLayer];
我想围绕形状本身内的轴旋转形状(上面的代码使我的小形状围绕距离实际中心几百个像素的轴旋转。
我觉得这应该用这样的锚点来控制:
shapeLayer.anchorPoint = CGPointMake(originx, originy);
但它似乎在代码中什么也没做。
有什么想法吗?
anchorPoint
是相对于图层边界的。您不能使用锚点来放置图层。相反,您可以相对于零点放置形状,旋转它,然后将其移动到所需的点。旋转和平移由变换完成。
我正在尝试原地旋转 CAShapeLayer
UIBezierPath *aPath = [UIBezierPath bezierPath];
CGFloat originx = (97.5+250);
CGFloat originy = (205+250);
[aPath moveToPoint:CGPointMake(originx,originy)];
[aPath addArcWithCenter:CGPointMake(originx+15, originy-30) radius:15 startAngle:DEGREES_TO_RADIANS(180) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
[aPath addLineToPoint:CGPointMake(originx+30,originy)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.anchorPoint = CGPointMake(originx, originy);
shapeLayer.path = [aPath CGPath];
shapeLayer.strokeColor = [[UIColor blueColor] CGColor];
shapeLayer.lineWidth = 3.0;
shapeLayer.fillColor = [[UIColor blueColor] CGColor];
[aPath closePath];
shapeLayer.transform = CATransform3DMakeRotation(310 * M_PI/180, 0.0, 0.0, 1.0);
[self.view.layer addSublayer:shapeLayer];
我想围绕形状本身内的轴旋转形状(上面的代码使我的小形状围绕距离实际中心几百个像素的轴旋转。
我觉得这应该用这样的锚点来控制:
shapeLayer.anchorPoint = CGPointMake(originx, originy);
但它似乎在代码中什么也没做。 有什么想法吗?
anchorPoint
是相对于图层边界的。您不能使用锚点来放置图层。相反,您可以相对于零点放置形状,旋转它,然后将其移动到所需的点。旋转和平移由变换完成。