出现的不是动画而是白屏

发布于 2024-10-21 04:06:52 字数 1911 浏览 1 评论 0原文

在我的应用程序中,我通过在 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];
}

In my app I am displaying animation by splitting .gif file into frames (to show animated splash) by writing this code in newAppDelegate.m

But when I run my app instead of animation white screen is coming and after 5 sec delay application starts.

- (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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淤浪 2024-10-28 04:06:53

我认为问题是

animatedImages.animationRepeatCount = -1;

您可能认为这会将重复计数设置为无穷大。然而,API 指出

默认值为 0,表示无限期重复动画。

I think the problem is

animatedImages.animationRepeatCount = -1;

You probably thought this would set the repeat count to infinity. However, the API states

The default value is 0, which specifies to repeat the animation indefinitely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文