删除CAKeyframeAnimation不会释放内存

nan*_*ano 5 iphone cocoa-touch core-animation uiimageview cakeyframeanimation

我将一个CAKeyframeAnimation添加到ImageView的图层,用于表示图像的动画:

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
animation.values = arrayOfImages;
[animation setRemovedOnCompletion:YES];
animation.delegate = self;
[animation setValue:delegate forKey:@"AnimatedImageViewDelegate"];
animation.repeatCount = repeatCount;
animation.fillMode = kCAFillModeForwards;
animation.calculationMode = kCAAnimationDiscrete;
[animation setValue:animationName forKey:@"name"];
Run Code Online (Sandbox Code Playgroud)

当我想开始动画时,我打电话:

animation.duration = duration;
[self.layer addAnimation:animation forKey:animationName];
[self.layer setContents:[animation.values lastObject]];
Run Code Online (Sandbox Code Playgroud)

当动画结束时,我想完全删除它并释放它的内存.

[self.layer removeAllAnimations];       
[self.layer removeAnimationForKey:animationName];
Run Code Online (Sandbox Code Playgroud)

这样做,并使用Instruments-Activity Monitor,除非我发布完整的imageView,否则不会重新启动内存.

如何在不破坏UIImageView的情况下释放动画内存?

Jes*_*ock 0

您正在使用便捷方法来实例化该对象。因此您将无法控制对象何时被实际释放。要对此进行控制,您需要自己分配对象并释放它:

创建实例:

CAKeyframeAnimation *animation = [[CAKeyframeAnimation alloc] init];
Run Code Online (Sandbox Code Playgroud)

然后在动画完成后,在删除线后调用:

[animation release];
Run Code Online (Sandbox Code Playgroud)