我将 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"];
当我想开始动画时,我调用:
animation.duration = duration;
[self.layer addAnimation:animation forKey:animationName];
[self.layer setContents:[animation.values lastObject]];
当动画结束时,我想完全删除它并释放它的内存。
[self.layer removeAllAnimations];
[self.layer removeAnimationForKey:animationName];
这样做并使用 Instruments-Activity Monitor,除非我释放完整的 imageView,否则内存不会释放。
如何在不破坏 UIImageView 的情况下释放动画内存???
最佳答案
您正在使用便捷方法来实例化该对象。因此您将无法控制对象何时被实际释放。要对此进行控制,您需要自己分配对象并释放它:
创建实例:
CAKeyframeAnimation *animation = [[CAKeyframeAnimation alloc] init];
然后在动画完成后,在删除行后调用:
[animation release];
关于iphone - 删除 CAKeyframeAnimation 不会释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9022015/