我正在使用 CAShapeLayer 绘制四分之一圆。单击时我想将其转换 90 度。但是当我这样做时,图层正在转换并且正在离开屏幕。我需要围绕中心点旋转。让我们假设中心点是 (100,100)。这是我的代码:
CGMutablePathRef path = CGPathCreateMutable();
//CGPathMoveToPoint(path, NULL, self.bounds.size.width/2, self.bounds.size.height/2);
CGPathAddArc(path, NULL, self.bounds.size.width/2, self.bounds.size.height/2, 100, (0), (M_PI_2), NO);
CGPathAddArc(path, NULL, self.bounds.size.width/2, self.bounds.size.height/2, 100-50, (M_PI_2), (0), YES);
CGPathCloseSubpath(path);
CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init];
arcLayer.path = path;
arcLayer.fillColor = [UIColor yellowColor].CGColor;
[self.layer addSublayer:arcLayer];
动画代码:
CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
spin.removedOnCompletion = NO;
spin.fillMode = kCAFillModeForwards;
[spin setByValue:[NSNumber numberWithFloat:M_PI_2]];
//layer.affineTransform = CGAffineTransformMakeRotation(M_PI_2);
[spin setDuration:1.0];
[layer addAnimation:spin forKey:@"transform.rotation"];
请帮我。