[英]EXC_BAD_ACCESS while using CoreAnimation
我使用CoreAnimation為UIImageView設置動畫(曲線Bezier動畫)。 這是我的代碼:
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
我嘗試使用其他手冊進行操作,但是應用程序崩潰的方式相同。 無法理解我的錯。 任何幫助將不勝感激,謝謝。
PS這是一個類似的錯誤 ,但不幸的是,僅通過刪除動畫即可解決。
PPS Arc已啟用。 另外,如果我評論pathAnimation.path = path.CGPath; 行,崩潰以及動畫都不會出現(不足為奇的:))。
當對象在內存中不存在時,將拋出該錯誤。 確保初始化是正確的方法? 確保您初始化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"];
將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;
好像是蘋果的蟲子
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.