CABasicAnimation与委托崩溃

时间:2011-03-18 13:22:20

标签: iphone delegates core-animation exc-bad-access

self.mLineAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
mLineAnimation.fromValue = (id)mStartPath;
mLineAnimation.toValue = (id)mEndPath;
mLineAnimation.duration = 2; 
mLineAnimation.repeatCount = 0;
[mLineAnimation setDelegate:self];
mLineAnimation.removedOnCompletion = NO;
mLineAnimation.fillMode = kCAFillModeForwards;
mLineAnimation.timingFunction = [CAMediaTimingFunction
                                    functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[mShapeLayer addAnimation: mLineAnimation forKey: @"animateLine"];

请注意,我设置了委托以实现animationDidStop。 我的动画在表格视图单元格中运行。 现在,当我快速滚动表格时,应用程序崩溃了EXC_BAD_ACCESS。 如果我没有设置委托,则应用程序不会崩溃。你能指导一下这里做什么吗?堆栈跟踪是下一个:

#0  0x0168ea63 in objc_msgSend
#1  0x056ff0a0 in ??
#2  0x00ee36cb in run_animation_callbacks
#3  0x00ee3589 in CA::timer_callback
#4  0x0150dfe3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__
#5  0x0150f594 in __CFRunLoopDoTimer
#6  0x0146bcc9 in __CFRunLoopRun
#7  0x0146b240 in CFRunLoopRunSpecific
#8  0x0146b161 in CFRunLoopRunInMode
#9  0x01cd9268 in GSEventRunModal
#10 0x01cd932d in GSEventRun
#11 0x003da42e in UIApplicationMain
#12 0x00002580 in main at main.m:14

1 个答案:

答案 0 :(得分:1)

动画在创建动画的对象被破坏后停止(“self”指向“self.mLineAnimation”中的对象)。然后动画尝试向被破坏的对象发送消息。

使用NSZombieEnabled运行您的可执行文件,这会将objc_MsgSend中的崩溃转换为会破坏调试器的Objective-C异常。