이것은 Core Animation에서 매우 쉽게 할 수 있습니다. 이 예제에서는 꽤 지루한 정적 값을 사용 했으므로 일부 수정을 원할 것입니다. 그러나 이것은 원형 UIBezierPath를 따라 뷰를 이동하는 방법을 보여줍니다.
UIView *view = [UIView new];
[view setBackgroundColor:[UIColor redColor]];
[view setBounds:CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)];
[view setCenter:[self pointAroundCircumferenceFromCenter:self.view.center withRadius:140.0f andAngle:0.0f]];
[self.view addSubview:view];
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(CGRectGetMidX(self.view.frame) - 140.0f, CGRectGetMidY(self.view.frame) - 140.0f, 280.0f, 280.0f)];
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = 5.0;
pathAnimation.path = [path CGPath];
[view.layer addAnimation:pathAnimation forKey:@"curveAnimation"];
그리고 뷰의 초기 중심을 생성하는 기본 함수.
- (CGPoint)pointAroundCircumferenceFromCenter:(CGPoint)center withRadius:(CGFloat)radius andAngle:(CGFloat)theta
{
CGPoint point = CGPointZero;
point.x = center.x + radius * cosf(theta);
point.y = center.y + radius * sinf(theta);
return point;
}