使用CoreAnimation时为EXC_BAD_ACCESS [英] EXC_BAD_ACCESS while using CoreAnimation

查看:100
本文介绍了使用CoreAnimation时为EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用CoreAnimation为UIImageView设置动画(曲线Bezier动画)。这是我的代码:

I use CoreAnimation to animate UIImageView (curve Bezier animation). Here`s my code:

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) with stacktrace:

As a result, I get EXC_BAD_ACCESS (code=2, address=0x0) with stacktrace:

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  

我尝试使用其他手册进行操作,但是应用崩溃的方式相同。无法理解我的错。谢谢您的帮助。

I tried to use different manuals to do it, but app crashes the same way. Can't understand where`s my fault. Any help will be appreciated, thanks.

P。 S。这是一个类似的 bug ,但不幸的是,仅通过删除动画即可解决该问题。

P. S. Here's a similar bug, but unfortunately it is solved just by removing animation.

P。 P. S.弧已启用。另外,如果我注释 pathAnimation.path = path.CGPath; 行,则不会出现崩溃以及动画(不出意外的是:))。

P. P. S. Arc is enabled. Also, if I comment pathAnimation.path = path.CGPath; line, crash does not appear, as well as animation (what is not surprised :) ).

推荐答案

用CABasicAnimation替换CAKeyframeAnimation:

Replace CAKeyframeAnimation with CABasicAnimation:

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

好像是苹果的虫子

这篇关于使用CoreAnimation时为EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆