我将 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 的情况下释放动画内存???