【问题标题】:EXC_BAD_ACCESS while using CoreAnimation使用 CoreAnimation 时的 EXC_BAD_ACCESS
【发布时间】:2013-08-03 13:46:43
【问题描述】:

我使用 CoreAnimation 为 UIImageView 制作动画(曲线贝塞尔动画)。这是我的代码:

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 (code=2, address=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  

我尝试使用不同的手册来执行此操作,但应用程序崩溃的方式相同。不明白我的错在哪里。任何帮助将不胜感激,谢谢。

P。 S.这里有一个类似的bug,可惜只是去掉动画就解决了。

P。 P. S. Arc 已启用。另外,如果我评论 pathAnimation.path = path.CGPath; 行,则不会出现崩溃以及动画(这并不奇怪:))。

【问题讨论】:

  • 您在项目中使用 ARC 吗?
  • 您能告诉我们 EXC_BAD_ACCESS 发生在哪一行吗? (一定要在 Xcode 中启用 All Exception Breakpoints)。
  • 崩溃发生在最后一行(断点和僵尸开启)

标签: ios core-graphics exc-bad-access uibezierpath cakeyframeanimation


【解决方案1】:

当对象在内存中不存在时会抛出该错误。确保你的初始化是正确的方式??确保初始化Layer..etc.. ?

最好的方法是使用 BreakPoint 找出您的应用程序在哪里被迷住了??

我不确定,但它可能对你有帮助。

将您的动画添加为

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"];

【讨论】:

  • 这一行发生崩溃:[star.layer addAnimation:pathAnimation forKey:@"moveToScorebarAnimation"];我也试过你的,但没有任何改变。
【解决方案2】:

将 CAKeyframeAnimation 替换为 CABasicAnimation:

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

似乎是苹果的错误

【讨论】:

  • 看起来像那样。谢谢!
  • 非常感谢.. 你拯救了我的一天。干杯。快乐编码。:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多