我在试着旋转一个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); 但在代码中它似乎什么也做不了。有什么想法吗?
发布于 2016-11-07 19:58:16
anchorPoint相对于层的边界。你不能使用锚点放置你的层。相反,您可以将您的形状相对于零点,旋转它,并将其移动到所需的点。旋转和平移是通过变换完成的。
https://stackoverflow.com/questions/40473356
复制相似问题