![](/img/trans.png)
[英]CAKeyframeAnimation over bezier curve stops (continually) when adBannerView is expanded
[英]CAKeyframeAnimation not calling animationDidStop after bezier curve (iOS)
我已经在这里(和整个网络)查看了针对我的情况的所有其他答案,但尚未解决该问题。 本质上发生的是我正在使包含图像的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 animation1在停止进行动画处理时会自动将animationDidStop方法发送给其指定的委托,这就是为什么我无法确定问题的原因。
我看到的所有其他解决方案或替代方案都无法使用或建议使用块动画,因此我无法找到在贝塞尔曲线上进行动画处理的方法。
在调用-[CALayer addAnimation:forKey:]
之前设置动画的委托。
注意CALayer.h
的注释:
在将动画添加到图层之前先对其进行复制,因此任何
除非对anim
进行后续的修改,否则将其无效,除非将其添加到另一层。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.