UIImage
의 배열에 CAKeyframeAnimation
으로 애니메이션을 적용하려고합니다. 쉬운 이론.
게시물 하단에 샘플 코드가 있습니다.CAKeyframeAnimation - 이미지 배열에 애니메이션을 적용하면 완료 후 큰 할당이 생성됩니다.
내 문제는 애니메이션이 끝난 후에는 제거 할 수없는 막대한 누출이 있다는 것입니다.
코드 CAKeyframeAnimation
를 초기화하기 위해서 그런 다음
... // Code to change
keyframeAnimation.delegate = self;
// keyframeAnimation.removedOnCompletion = YES;
keyframeAnimation.removedOnCompletion = NO;
keyframeAnimation.fillMode = kCAFillModeForwards;
....
:
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
if (flag)
{
[self.animationImageView.layer removeAllAnimations];
[self.animationImageView.layer removeAnimationForKey:@"flingAnimation"]; // just in case
}
}
- (void)animateImages
{
CAKeyframeAnimation *keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
keyframeAnimation.values = self.imagesArray; // array with images
keyframeAnimation.repeatCount = 1.0f;
keyframeAnimation.duration = 5.0;
keyframeAnimation.removedOnCompletion = YES;
CALayer *layer = self.animationImageView.layer;
[layer addAnimation:keyframeAnimation
forKey:@"flingAnimation"];
}
애니메이션에 대리인을 추가 및 애니메이션을 제거 수동으로 같은 누출 효과의 원인
결과는 다음과 같습니다. 엄청난 배당금. 메모리 적층 체의 크기는 이미지의 크기에 비례한다 :
I uploaded an example to GitHub to check the code.
나는 악기를 실행하고 거기에는 누수가 없지만 할당이 높다. – gabbler
높은 할당량을 해결하는 방법을 알고 있습니까? –
대신'imageWithContentsOfFile'을 사용하십시오. – gabbler