2012-12-29 1 views
0

다음 코드는 타원형을 중심으로 회전시킵니다. 특정 위치 (보기의 중간 부분)에서 UIImageView 내에 위치를 지정하고 싶습니다.UIImageView의 특정 지점에서 회전하는 CAShapeLayer를 배치하는 방법은 무엇입니까?

누군가 나를 도와 줄 수 있다면 정말 고맙겠습니다.

-(void)drawCircle 
{ 
CGMutablePathRef circlePath = CGPathCreateMutable(); 
int radius = 400; 
CGRect circleRect = CGRectMake(CENTER_Y-radius*0.7, CENTER_X-radius, 1.4*radius, 2*radius); 
float midX = CGRectGetMidX(circleRect); 
float midY = CGRectGetMidY(circleRect); 

CGAffineTransform transform = CGAffineTransformMakeTranslation(-midX, -midY); 
CGPathAddEllipseInRect(circlePath ,&transform , circleRect); 

CAShapeLayer *circle = [[CAShapeLayer alloc] init]; 
circle.path = circlePath; 
circle.opacity = 0.1; 
circle.contentsScale = SCREEN_SCALE; 
circle.fillColor = [UIColor blueColor].CGColor; 

[aView.layer addSublayer:circle]; 
CABasicAnimation* theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; 
theAnimation.fromValue = 0; 
theAnimation.toValue = @(2*M_PI); 
theAnimation.duration=3.5; 
theAnimation.autoreverses=FALSE; 
theAnimation.repeatCount=HUGE_VALF; 
theAnimation.fillMode = kCAFillModeBoth; 
theAnimation.removedOnCompletion=FALSE; 
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
[circle addAnimation:theAnimation forKey:@"transform.rotation.z"]; 

} 

답변

0

누락 된 조각 :

[circle setPosition:CGPointMake(CENTER_X, CENTER_Y)]; 
+0

질문이나 질문에 대한 실제 대답의 일부인가? 질문에 대한 추가 정보는 답변에 더 많은 정보를 게시하는 대신 질문을 편집해야합니다. 질문의 왼쪽 아래에있는 편집 버튼 –

+0

은 내 질문에 대한 대답입니다. – GrAnD

+0

모양 레이어의 경계를 설정하지 않은 것처럼 보입니다. '[circle setBounds : circleRect]; '그래서 나는 그것이 전혀 표시되지 않는다는 것에 놀랐습니다. –

관련 문제