而不是动画白屏即将到来

时间:2011-03-11 12:00:32

标签: iphone objective-c splash-screen animated-gif

在我的应用程序中,我通过在newAppDelegate.m中编写此代码将.gif文件拆分为帧(以显示动画启动)来显示动画

但是当我运行我的应用而不是动画白屏时,5秒后应用程序启动延迟。

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Array to hold jpg images
    imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];

    // Build array of images, cycling through image names

    imageArray = [NSMutableArray arrayWithObjects: [UIImage imageNamed:@"f1.jpg"], [UIImage imageNamed:@"f2.jpg"], [UIImage imageNamed:@"f3.jpg"], [UIImage imageNamed:@"f4.jpg"], [UIImage imageNamed:@"f5.jpg"], [UIImage imageNamed:@"f6.jpg"], nil];
    NSLog(@"total image:%d", imageArray.count);

    // Animated images - centered on screen
    animatedImages = [[UIImageView alloc] 
                      initWithFrame:CGRectMake(
                                               (SCREEN_WIDTH / 2) - (IMAGE_WIDTH / 2), 
                                               (SCREEN_HEIGHT / 2) - (IMAGE_HEIGHT / 2) + STATUS_BAR_HEIGHT,
                                               IMAGE_WIDTH, IMAGE_HEIGHT)];
    animatedImages.animationImages = [NSArray arrayWithArray:imageArray];

    // One cycle through all the images takes 1.5 seconds
    animatedImages.animationDuration =1;

    // Repeat forever
    animatedImages.animationRepeatCount = -1;

    // Add subview and make window visible
    [window addSubview:animatedImages];
    [window setBackgroundColor:[UIColor blackColor]];
    [window makeKeyAndVisible];

    // Start it up
    [animatedImages startAnimating];

    // Wait 5 seconds, then stop animation
    [self performSelector:@selector(stopAnimation) withObject:nil afterDelay:5.0];

}

- (void)stopAnimation
{
    [animatedImages stopAnimating];
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
}

1 个答案:

答案 0 :(得分:1)

我认为问题是

animatedImages.animationRepeatCount = -1;

您可能认为这会将重复次数设置为无穷大。但是,API声明

  

默认值为0,指定无限期重复动画。