2013-09-24 4 views
1

나는 4 분의 1 원을 그렸다. 이를 위해 UIView의 중심을 중심으로 사용했습니다. 그림을 그리는 것이 좋습니다.
이제 경로에 애니메이션을 적용하고 싶습니다. 그래서 KeyFrame 애니메이션을 사용했습니다.
문제는 CAShapeLayer의 중심에서 회전하고 있다는 것입니다. 나는 싫어. 나는 국경 주위에 cgpath를 회전시키고 싶다. 초기 위치에서 보아라. 맞다. 그러나 경로에서 회전을 시작하면 CAShapeLayer의 중심을 따라 경로를 따라 회전합니다.경로 애니메이션 CAShapeLayer

 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.backgroundColor = [UIColor whiteColor].CGColor; 
    arcLayer.bounds = CGPathGetPathBoundingBox(path); 

내가 gesture.Here이 애니메이션 코드 단일 탭에 애니메이션을 응시하고있다 : 마지막으로 내가 네

- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{ 
    CGPoint touchPoint=[gesture locationInView:self]; 
    NSArray* subLayerArray = [pathLayer 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, self.bounds.size.height/2, 100, 0, 3*M_PI/2, NO); 
     CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
     anim.path = path; 
     anim.rotationMode = kCAAnimationRotateAutoReverse; 
     anim.fillMode = kCAFillModeForwards; 
     anim.removedOnCompletion = NO; 
     anim.duration = 100.0; 
     [layer addAnimation:anim forKey:@""]; 
     } 
    } 
    } 

Initial postion during rotaion

+1

다시 같은 질문을하지 마십시오. 더 많은 정보가 있으면 기존 질문을 수정하십시오. – jrturton

답변

0

여기

노란색 분기 코드 해결책을 찾았어요. 우리는 층의 앵커 포인트를 잊지 않습니다. 앵커 포인트를 설정해야합니다. arcLayer.anchorPoint = CGPointMake(0 , 1);. 희망이 도움이 될 것입니다 ...

관련 문제