저는 CAShapeLayer를 사용하여 그려진 원호를 원 중심에서 회전시키고 싶습니다. 'transform.rotation'속성에 CABasicAnimation을 사용하여이 애니메이션을 가져 오려고합니다. 그러나 회전은 원의 중심과 같지 않은 지점에서 일어난 것처럼 보입니다. CABasicAnimation을 사용하여 CAShapeLayer 호를 중심으로 회전
-(void)drawRect:(CGRect)rect{
int radius = 100;
CAShapeLayer *circle = [CAShapeLayer layer];
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;
circle.fillColor = [UIColor orangeColor].CGColor;
circle.strokeColor = [UIColor blueColor].CGColor;
circle.lineWidth = 5;
circle.strokeStart = 0.0f;
circle.strokeEnd = 0.1f;
[self.layer addSublayer:circle];
CABasicAnimation *spinAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
spinAnimation.byValue = [NSNumber numberWithFloat:2.0f*M_PI];
spinAnimation.duration = 4;
spinAnimation.repeatCount = INFINITY;
[circle addAnimation:spinAnimation forKey:@"indeterminateAnimation"];
}
나는 그에게 오래된 문제를 알고 있지만 무슨 방법 알아. 레이어의 경계 또는 앵커 포인트를 설정하여 많은 문제가 발생했지만 아직 센터를 중심으로 회전하지 않습니다.
circle.bounds = self.frame;
다음은보기 컨트롤러에보기를 추가하는 방법입니다.
[self.view addSubview:[[ProgressIndicator alloc] initWithFrame:CGRectMake(50, 50, 200, 200)]];