Ios 围绕UIView的中心旋转CAShapeLayer

Ios 围绕UIView的中心旋转CAShapeLayer,ios,animation,cashapelayer,Ios,Animation,Cashapelayer,我正在制作CAShapeLayer的动画。我正在画第1象限的四分之一圆(参考图)(据我所知)。现在我想把它旋转90度,这样它就可以固定在第二象限,并在单次点击动作中显示动画。我试过了,但没有固定到第二象限。我想绕视图的中心旋转 单点击手势: - (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture { CGPoint touchPoint=[gesture locationInView:self]; NS

我正在制作CAShapeLayer的动画。我正在画第1象限的四分之一圆(参考图)(据我所知)。现在我想把它旋转90度,这样它就可以固定在第二象限,并在单次点击动作中显示动画。我试过了,但没有固定到第二象限。我想绕视图的中心旋转

单点击手势:

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture {
    CGPoint touchPoint=[gesture locationInView:self];
    NSArray* subLayerArray = [self.layer sublayers];
    for (int i = 0; i < subLayerArray.count; i++) {
        CAShapeLayer* layer = [subLayerArray objectAtIndex:i];

        if(CGPathContainsPoint(layer.path, NULL, touchPoint, NO)){
            CGMutablePathRef path = CGPathCreateMutable();
            CGPathAddArc(path, NULL, self.bounds.size.width/2-layer.frame.size.width/2, self.bounds.size.height/2-layer.frame.size.height/2, 100, 0*M_PI, M_PI, YES);            
            CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
            anim.path = path;
            anim.rotationMode = kCAAnimationRotateAuto;
            anim.calculationMode = kCAAnimationPaced;
            anim.fillMode = kCAFillModeForwards;
            anim.removedOnCompletion = NO;
            anim.duration = 10.0;
            [layer addAnimation:anim forKey:@""];
        }
    }
}
和图像:


为什么不简单地设置
transform.rotation.z
关键路径的动画呢?我想绕UIView的中心旋转,而不是它自己的中心。用正确的中心旋转superview?不是superview。实际上我正在绘制4-5个级别的圆环图。因此,当用户点击任何cashapelayer时,我想旋转该级别。如果我像你那样做的话说“旋转superview”,然后我的所有级别都将旋转,我不想旋转。我只想旋转用户选择的级别。您可以随时更改(但可能会有副作用,例如视图在正确操作之前移动其位置),或者您可以使每个视图足够大,使其中心位于父视图的中心。
- (void)drawRect:(CGRect)rect {
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100, (0), (M_PI_2), NO);
    CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100-50, (M_PI_2), (0), YES);
    CGPathCloseSubpath(path);
    CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init];
    arcLayer.path = path;
    arcLayer.frame = CGPathGetPathBoundingBox(path);
    arcLayer.fillColor = [UIColor yellowColor].CGColor;
    arcLayer.bounds = CGPathGetPathBoundingBox(path);
    [self.layer addSublayer:arcLayer]; 
}