【发布时间】:2015-01-02 14:37:49
【问题描述】:
我的视图中有两个 imageViews 并与 IBOutlet 连接:
IBOutlet UIImageView *ship; // X/Y = 130/82, W/H = 61/50
IBOutlet UIImageView *planet;// X/Y = 87/173, W/H = 147/128
我要做的就是让我的飞船图像沿着椭圆路径(使用行星图像创建)制作动画,为此:
CAKeyframeAnimation *orbit = [CAKeyframeAnimation animation];
orbit.keyPath = @"position";
orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(planet.bounds, NULL));
orbit.duration = 4;
orbit.additive = YES;
orbit.repeatCount = HUGE_VALF;
orbit.calculationMode = kCAAnimationPaced;
orbit.rotationMode = kCAAnimationRotateAuto;
[ship.layer addAnimation:orbit forKey:@"orbit"];
代码的问题是我的船图像在我的星球图像之外进行动画处理,为了解决这个问题,我使用以下方法手动执行此操作:
CGRect boundingRect = CGRectMake(-100, 30, 200, 200);
orbit.path = CFAutorelease(CGPathCreateWithEllipseInRect(boundingRect, NULL));
现在,如果我的星球位于 X/Y = 130/82,为什么还要使用 X/Y = -100/30?有另一种直接通过图像执行此操作的方法(例如planet.layer.bounds 或planet.frame)吗?
【问题讨论】:
标签: objective-c core-animation quartz-core cgpath cakeyframeanimation