Iphone 模拟动画内存不足
我正在尝试基于一系列54幅图像模拟动画。我收到一条“程序接收信号:”0“。消息-内存不足 我正在尽力照顾他们,因为我似乎失败了。我在大约4-5秒内完成了所有54个步骤,然后应该会重复(几乎像一本翻页书)。由于图像中有闪亮的3D材质,因此使用核心动画无法轻松完成动画 或者,有没有更好的办法 代码如下:Iphone 模拟动画内存不足,iphone,image,ipad,uiimage,nstimer,Iphone,Image,Ipad,Uiimage,Nstimer,我正在尝试基于一系列54幅图像模拟动画。我收到一条“程序接收信号:”0“。消息-内存不足 我正在尽力照顾他们,因为我似乎失败了。我在大约4-5秒内完成了所有54个步骤,然后应该会重复(几乎像一本翻页书)。由于图像中有闪亮的3D材质,因此使用核心动画无法轻松完成动画 或者,有没有更好的办法 代码如下: -(void)addImage:(NSString*)imageName{ if (self.images == nil){ self.images = [[[NSMutab
-(void)addImage:(NSString*)imageName{
if (self.images == nil){
self.images = [[[NSMutableArray alloc] init] autorelease];
}
[self.images addObject:[UIImage imageNamed:imageName]];
}
// Returns a UIImageView that contains the next image to display
- (UIImageView *)nextImageView
{
// get the image at the next index
UIImage *image = [images objectAtIndex:pictureIndex];
++pictureIndex; // increment the index
if(pictureIndex > images.count -1){
pictureIndex = 0;
}
// create an image view for the image
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
// resize the image to fill the screen without distorting
imageView.frame = rotator.frame;
imageView.autoresizesSubviews = NO;
[imageView setContentMode:UIViewContentModeCenter];
// Makes the image move proportionally in any direction if the
// bounds of the superview change when the iPhone is rotated.
imageView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
return imageView;
}
- (void)timerFired:(NSTimer *)_timer{
UIImageView *nextImageView = [self nextImageView];
if(nextImageView){
[self.view addSubview:nextImageView];
nextImageView.alpha = 0.0;
//NSLog(@"timerFired - image no: %i", pictureIndex);
// begin animation block
[UIView beginAnimations:nil context:nextImageView];
[UIView setAnimationDuration:animationDuration]; // set the animation length
[UIView setAnimationDelegate:self]; // set the animation delegate
// call the given method when the animation ends
[UIView setAnimationDidStopSelector:@selector(transitionFinished:finished:context:)];
// make the next image appear with the chosen effect
[nextImageView setAlpha:1.0]; // fade in the next image
[currentImageView setAlpha:0.0]; // fade out the old image
[UIView commitAnimations];
} else {
[timer invalidate];
timer = nil;
}
}
// called when the image transition animation finishes
- (void)transitionFinished:(NSString *)animationId finished:(BOOL)finished context:(void *)context
{
[currentImageView removeFromSuperview]; // remove the old image
[currentImageView release]; // release the memory for the old image
currentImageView = context; // assign the new image
}
-(void)startRotator{
self.rotator.animationImages = self.images;
self.rotator.animationDuration = animationDuration;
pictureIndex = 0; // reset the index
currentImageView = [self nextImageView]; // load the first image
[self.view addSubview:currentImageView]; // add the image to the view
//[self.rotator startAnimating];
NSLog(@"start Animating - Image Count: %i", self.images.count);
timer = [NSTimer scheduledTimerWithTimeInterval:scheduledInterval
target:self
selector:@selector(timerFired:)
userInfo:nil
repeats:YES];
}
您正在
nextImageView
中泄漏imageView
。返回的实例应自动删除
你确定你的54幅图像适合memeory吗?还要记住,大多数图像格式都未经压缩存储在iPhone的内存中,因此它们占用的内存可能比你意识到的要多。iOS可以将压缩后的PVRTC图像存储在内存中,但它们也有自己的折衷方案。它将在transitionFinished中发布。我能够把它们全部缩小,这似乎起到了作用。你能告诉我更多关于PVRTC的情况吗?