【发布时间】:2014-09-02 17:06:57
【问题描述】:
我正在通过构建多个 CALayers 来构建照片幻灯片,将 cgimage 分配给图层的内容,然后将 CAAnimations 添加到每个图层。每一层都脱落并开始时间并在持续时间之后(比如 3 秒)。没有一个动画在时间上重叠。最后将所有图层添加到 AVSynchronizedLayer 中,以便使用 AVPlayer 进行播放。
问题:如何在相应动画运行时延迟图像加载?目前我在构建每一层时都会执行 imageLayer.contents = (id) self.image.CGImage ,无论它是否在屏幕上可见,它都会增加内存使用量。
我还尝试通过为 contents 属性设置动画来设置 CALayer 内容,如下所示:
CABasicAnimation *contentsAnimation = [CABasicAnimation animationWithKeyPath:@"contents"];
contentsAnimation.beginTime = startTime;
contentsAnimation.duration = CMTimeGetSeconds(self.timeRange.duration);
contentsAnimation.fromValue = (id) self.photoImage.CGImage;
contentsAnimation.toValue = (id) self.photoImage.CGImage;
contentsAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
contentsAnimation.fillMode = kCAFillModeForwards;
contentsAnimation.removedOnCompletion = NO;
[imageLayer addAnimation:contentsAnimation forKey:@"contents"];
但问题是由于引用了 CGImage,它增加了内存使用量。如果你有 20 张图片,脏内存的大小会导致崩溃。
【问题讨论】:
标签: calayer avplayer cgimage caanimation