2016-11-07 1 views
0

내가 자리에 CAShapeLayer을 회전하기 위해 노력하고있어회전 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]; 

나는 모양 자체 (위의 코드 내 작은 모양 백 개 픽셀 몇 가지 축을 중심으로 회전하게 내 축을 중심으로 모양을 회전 할 . 실제 중심에서

나는이이 하나의 같은 anchorpoint으로 제어한다고 생각 :

shapeLayer.anchorPoint = CGPointMake(originx, originy); 

하지만 코드 내에서 아무것도하지 않는 것 같다.아이디어가 있습니까?

답변

1

anchorPoint은 레이어의 경계를 기준으로합니다. 고정 점을 사용하여 레이어를 배치 할 수 없습니다. 대신 모양을 원점에 상대적으로 배치하고 회전하고 원하는 점으로 이동시킬 수 있습니다. 회전 및 평행 이동은 변형에 의해 수행됩니다.

+0

그래서 1 : 장소 2) 변형 3) 이동? – stevenpcurtis

+0

네, 마지막 두 작업은 두 개의 변환을 연결 한 것입니다. (팁 : 테스트 및 디버깅을 위해 더 작은 각도 (예 : 5 °)로 시작하는 것이 더 쉽습니다. 레이어가 잘못된 방향으로 움직이는 지 알 수 있습니다.) – clemens

+0

흠 나는 이것을 수행 할 수있는 유일한 방법은 먼저 이동하는 것입니다. . CATransform3D translate = CATransform3DMakeTranslation (52.7, 45.46, 0); 이 작업을 수행해야하지만 그렇지 않습니다. – stevenpcurtis