【发布时间】:2010-12-15 16:33:08
【问题描述】:
我已经见过How to identify CAAnimation within the animationDidStop delegate?,这是对它的补充。
我无法让它正常工作。我有一个动画,我想在动画结束后释放它运行的控制器。 示例:控制器从右 -> 左平移然后释放自身。
定义动画:
NSValue *end = [NSValue valueWithCGPoint:CGPointMake(800, self.view.center.y)];
NSValue *start = [NSValue valueWithCGPoint:self.view.center];
CABasicAnimation *moveAnimation;
moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
moveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
moveAnimation.duration = 0.45f;
moveAnimation.fromValue = start;
moveAnimation.toValue = end;
// actually set the position
[self.view.layer setPosition:[end CGPointValue]];
moveAnimation.delegate = self;
moveAnimation.removedOnCompletion = NO;
[self.view.layer addAnimation:moveAnimation forKey:MOVING_OUT];
委托方法内部:
- (void) animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
{
CAAnimation *check = [self.view.layer animationForKey:MOVING_OUT];
if (theAnimation == check)
{
//[check release];
[self release];
}
}
如果我按原样保留此代码,我的控制器不会被释放(由于动画的保留调用)。
如果我运行[check release],我会得到message sent to deallocated instance。
有谁知道怎么回事?
是否有另一种方法可以在 animationDidStop 委托中识别 CAAnimation 而无需指定 removedOnCompletion = NO?
编辑:
忘了提。通过不指定 removedOnCompletion = NO,animationForKey: 将返回 NULL。因此我无法识别动画。
谢谢!
【问题讨论】:
标签: iphone objective-c core-animation core-graphics