【问题标题】:Ipad animating images crashing issueIpad动画图像崩溃问题
【发布时间】:2011-04-27 05:33:38
【问题描述】:

我有一个应用程序,其中我将 imageview 作为背景,在该 imageview 中我使用 89 个图像来制作动画。这是我制作动画的代码

-(void)viewWillAppear:(BOOL)animated
{

NSString *cachesDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];    
NSLog(@"cachesDirectoryPath: %@", cachesDirectoryPath);
    CPIAppDelegate *obj=(CPIAppDelegate *)[[UIApplication sharedApplication]delegate];
    arrayOfImages=[[NSMutableArray alloc]init];

    viewMenu.hidden = obj.buttonStatus;
    for (int i=0; i<IMAGE_ANIMATION_COUNT; i++) {
//  [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/streamvideo351_frame%d.jpg",cachesDirectoryPath,i]];
        [arrayOfImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"streamvideo351_frame%d.jpg",i]]];

    }

    BackGrdImage.animationImages=arrayOfImages;
    BackGrdImage.animationDuration =5.0; 
    BackGrdImage.animationRepeatCount =3;
    [BackGrdImage startAnimating];
    [arrayOfImages removeAllObjects];

}

在我正在使用的 dealloc 方法中

[imageAnimations release];
[BackGrdImage removeFromSuperview];
[BackGrdImage release];

它在模拟器上运行良好但在 Ipad 上崩溃。ipad 中实际发生的情况是有时它会闪烁,有时它会消失。所以请帮我解决这个问题。我也在 -(void)viewWillDisappear 上发布数组所以请朋友帮我解决一下。任何帮助或建议将不胜感激。

【问题讨论】:

  • 可能不是问题,但请确保在 viewWillAppear: 方法的某个时间点调用 [super viewWillAppear:animated]。

标签: iphone objective-c ios4 animation


【解决方案1】:

你的应用程序崩溃了,因为 BackGrdImage 在你释放数组之后只动画一次

[arrayOfImages removeAllObjects];

BackGrdImage.animationRepeatCount =3;

因此,您的图像会第二次进行动画处理,但 BackGrdImage 没有为动画获取 arrayOfImages,因此您的应用程序将崩溃。

当您的图像动画三次意味着在 1.5 秒内,然后您必须调用一种方法来释放您的 arrayOfImages 时,有一种方法。 上面的过程肯定会成功的。

【讨论】:

    【解决方案2】:

    可能是您收到内存警告。因为我不认为该设备将支持 89 个图像/图像视图的图像数组。尝试在设备上调试您的应用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多