【发布时间】:2011-11-06 22:27:51
【问题描述】:
所以我当前的版本是这样的:Animation Movie
我对核心动画还很陌生,所以我试图实现的是有多个点,就像当前的一样,从左边的盒子以不同的角度、高度和速度移动出来,就像网球一样球机。
第一个问题是,我的“球”看起来不像是被重力抓住的,而且一开始的速度也不够快。
另外,如何在起点之间的距离不同的情况下多次执行此动画。
如果有不清楚的地方,请发表评论。
我当前的代码:
- (void)loadView {
[super loadView];
self.view.backgroundColor = [UIColor lightGrayColor];
CGPoint startPoint = CGPointMake(20, 300);
CGPoint endPoint = CGPointMake(300, 500);
UIBezierPath *trackPath = [UIBezierPath bezierPath];
[trackPath moveToPoint:startPoint];
[trackPath addQuadCurveToPoint:endPoint controlPoint:CGPointMake(endPoint.x, startPoint.y)];
CALayer *point = [CALayer layer];
point.bounds = CGRectMake(0, 0, 20.0, 20.0);
point.position = startPoint;
point.contents = (id)([UIImage imageNamed:@"point.png"].CGImage);
[self.view.layer addSublayer:point];
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anim.path = trackPath.CGPath;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
anim.repeatCount = HUGE_VALF;
anim.duration = 2.0;
[point addAnimation:anim forKey:@"movepoint"];
CALayer *caseLayer = [CALayer layer];
caseLayer.bounds = CGRectMake(0, 0, 140.0, 150.0);
caseLayer.position = startPoint;
caseLayer.contents = (id)([UIImage imageNamed:@"case.png"].CGImage);
[self.view.layer addSublayer:caseLayer];
}
【问题讨论】:
-
我建议你看看使用cocos2d/box2d 来运行你的“动画”作为物理模拟。如果您想要逼真的重力和粒子运动,这就是它听起来应该的样子。
-
我认为我不需要这样的依赖。它仅适用于我的应用程序中的一个(并且不是很重要)视图。
-
由于您尝试将基本物理特性融入球中,使用 CADisplayLink 并为球设置动画会反复改变其位置是否可以接受?有人反对这个解决方案吗?
标签: iphone objective-c ios animation core-animation