ich den folgenden Code bin mit dem Begrüßungsbildschirm anzuzeigen:Speicherproblem für Bild-Animation mit GIF - ios
UIImageView *defaultImage = [[UIImageView alloc] init];
defaultImage.frame = defaultImageFrame;
// for iOS 9 Compatability
//NSMutableArray *buttonsArray = [[NSMutableArray alloc] initWithCapacity:1];
NSMutableArray *buttonsArray = [NSMutableArray arrayWithCapacity:1];
for (int i = 1; i<=3; i++)
{
[buttonsArray addObject:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"img00%d", i] ofType:@"png"]]];
}
mAnimatedButtons = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_DEVICE, HEIGHT_DEVICE)];
[mAnimatedButtons setUserInteractionEnabled:NO];
[mAnimatedButtons setAnimationImages:buttonsArray];
[mAnimatedButtons setAnimationRepeatCount:0];
[mAnimatedButtons setAnimationDuration:2.0];
[mAnimatedButtons startAnimating];
[defaultImage addSubview:mAnimatedButtons];
[self.view addSubview:defaultImage];
und ich werde den Splash-Screen nach diesem
[mAnimatedButtons stopAnimating]; //here animation stops
[mAnimatedButtons removeFromSuperview]; // here view removes from view hierarchy
mAnimatedButtons = nil;
self.defaultImage=nil;
[self.defaultImage removeFromSuperview];
[self.view.layer removeAllAnimations];
for (CALayer* layer in [self.view.layer sublayers])
{
[layer removeAllAnimations];
}
Hinzufügen dieser Code entfernen erhöht den Speicherverbrauch auf bis zu 300 MB. Entfernen von diesem hat es nur 100 MB.
Ich habe versucht, den folgenden Code auch
self.defaultImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH_DEVICE, HEIGHT_DEVICE)];
self.defaultImage.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"img001.png"],
[UIImage imageNamed:@"img002.png"],
[UIImage imageNamed:@"img003.png"],
nil];
//self.defaultImage.animationDuration = 1.0f;
self.defaultImage.animationRepeatCount = 0;
[self.defaultImage setAnimationDuration:2.0];
[ self.defaultImage startAnimating];
[self.view addSubview: self.defaultImage];
Auch wenn das Ergebnis gleich ist.
Wie groß sind Ihre Bilder? – random
1081 × 1921 Pixel, und mit Speicher von 200 kb, 800kb, 108kb – Gokulnath
Gibt es einen Grund, warum Sie 'mimatedButtons' als Unteransicht zu' defaultImage' hinzufügen? Warum nicht einfach ein einzelnes 'UIImageView' verwenden? Durch den Aufruf von 'removeFromSuperview' wird auch die Ansicht aus dem Speicher freigegeben, so dass 'self.defaultImage = nil' nicht mehr benötigt wird. – random