【发布时间】:2014-04-07 01:46:23
【问题描述】:
我已经查看了此处(以及整个网络)针对我的情况的所有其他答案,但尚未解决该问题。基本上正在发生的是我在二次贝塞尔曲线上为包含图像的 CALayer 设置动画。动画效果很好,但我真的需要实现动画后的行为,我所做的每一次尝试都失败了。这是我的代码:
UIBezierPath *path1 = [UIBezierPath bezierPath];
[path1 moveToPoint:P(67, 301)];
[path1 addQuadCurveToPoint:P(254, 301) controlPoint:P(160, 93)];
CALayer *ball1 = [CALayer layer];
ball1.bounds = CGRectMake(67, 301, 16.0, 16.0);
ball1.position = P(67, 301);
ball1.contents = (id)([UIImage imageNamed:@"turqouiseBallImage.png"].CGImage);
[self.view.layer addSublayer:ball1];
CAKeyframeAnimation *animation1 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation1.path = path1.CGPath;
animation1.rotationMode = kCAAnimationRotateAuto;
animation1.repeatCount = 2.0;
animation1.duration = 5.0;
[ball1 addAnimation:animation1 forKey:@"ball1"];
[animation1 setDelegate:self];
我正在尝试将动画的委托设置为 self(我的主视图控制器;这一切都在 viewDidLoad 中),其代码实现了 animationDidStop 方法:
(interface) (only showing relevant code)
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag;
(implementation)
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag; {
NSLog(@"animation did stop");
}
我看不出我在做什么导致方法不被调用。根据我的理解(我对 iOS 编程相当陌生,当然),CAKeyFrameAnimation 动画 1 在停止动画时会自动将 animationDidStop 方法发送给其指定的委托,这正是我无法识别问题的原因。
我见过的所有其他解决方案或替代方案要么不起作用,要么建议使用块动画,为此我找不到在贝塞尔曲线上制作动画的方法。
【问题讨论】:
标签: ios objective-c animation uibezierpath cakeyframeanimation