-->

同时采用EXC_BAD_ACCESS CoreAnimation(EXC_BAD_ACCESS wh

2019-10-18 11:15发布

我使用CoreAnimation动画的UIImageView(曲线贝塞尔动画)。 Here`s我的代码:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationCubic;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;

CGPoint endPoint = originalPosition;

UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:star.layer.position];
[path addQuadCurveToPoint:endPoint controlPoint:CGPointMake(star.layer.position.x, endPoint.y)];

pathAnimation.path = path.CGPath;

[star.layer addAnimation:pathAnimation forKey:@"moveToScorebarAnimation"];

其结果是,我得到EXC_BAD_ACCESS(代码= 2,地址=为0x0)与堆栈跟踪:

CoreGraphics`CG::Path::apply(void*, void (*)(void*, CGPathElementType, CGPoint const*)) const:
0x613c06:  pushl  %ebp
0x613c07:  movl   %esp, %ebp
0x613c09:  subl   $24, %esp
0x613c0c:  movl   8(%ebp), %eax
0x613c0f:  movl   (%eax), %ecx
0x613c11:  movl   (%ecx), %eax
0x613c13:  movl   16(%ebp), %edx
0x613c16:  movl   %edx, 8(%esp)
0x613c1a:  movl   12(%ebp), %edx
0x613c1d:  movl   %edx, 4(%esp)
0x613c21:  movl   %ecx, (%esp)
0x613c24:  calll  *64(%eax)
0x613c27:  addl   $24, %esp
0x613c2a:  popl   %ebp
0x613c2b:  ret  

我试图用不同的手册来做到这一点,但应用程序崩溃,以同样的方式。 where`s我的错,无法理解。 任何帮助将不胜感激,谢谢。

PS这里有一个类似的错误 ,但不幸的是它仅仅是通过去除动画解决。

PPS弧启用。 另外,如果我评论pathAnimation.path = path.CGPath; 线,崩溃没有出现,以及动画(什么是不惊讶:))。

Answer 1:

当对象不存在于内存中的错误将被抛出。 确保你初始化有道? 请确保您初始化Layer..etc..

最好的办法是使用断点找出你的应用程序来粉碎?

我不知道,但它可能对你有所帮助。

添加您的动画作为

CAAnimationGroup *group = [CAAnimationGroup animation];
group.animations = [NSArray arrayWithObjects: pathAnimation,nil];
group.duration = 7.0;  //The total time of the animations, don't know if redundant
group.delegate = self;

[self.layer addAnimation:group forKey:@"path"];


Answer 2:

与CABasicAnimation替换CAKeyframeAnimation:

 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
 pathAnimation.fromValue = [NSValue valueWithCGPoint:star.layer.position];
 pathAnimation.toValue = [NSValue valueWithCGPoint:endPoint];
 pathAnimation.fillMode = kCAFillModeForwards;
 pathAnimation.removedOnCompletion = NO;

似乎这是苹果的bug



文章来源: EXC_BAD_ACCESS while using CoreAnimation