启动屏幕和第一个视图控制器之间出现意外延迟

发布于 2024-08-22 14:57:11 字数 2009 浏览 7 评论 0原文

我有一个标签栏应用程序。这是我的代码

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[application setStatusBarHidden:YES animated:NO];
[self showSplashView];
}
- (void)showSplashView {
//If i don't use black view it displays white screen thats look so bad...
   UIView* blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
blackView.backgroundColor = [UIColor blackColor];
[window addSubview:blackView]; // sends [blackView retain]
[blackView release];

splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"MyImage.png"];
    [window addSubview:splashView];
    [window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil ];
[UIView setAnimationDelay:5.0];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
   [UIView setAnimationDelegate:self];
   [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:) ];
   splashView.alpha = 0.0;
   splashView.frame = CGRectMake(-60, -60, 440, 600);

   [UIView commitAnimations];

  }
  - (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
UIView* blackView = [[window subviews] objectAtIndex:0];
    [blackView removeFromSuperview];
    [splashView removeFromSuperview];
    [splashView release];
[window addSubview:tabBarController.view];
[window makeKeyWindow];
 }

,所以我的问题是当我的应用程序首先启动时它显示黑屏,几秒钟后它显示我的启动图像。当闪屏动画再次完成时,它显示黑屏,几秒钟后它显示我的视图控制器。我不知道为什么会发生这种情况。我希望我的问题很清楚。 谢谢 编辑 我的预期行为是应用程序启动后,它应该显示我的启动屏幕而不是黑屏,并且启动动画完成后,它应该显示我的第一个视图控制器(这是第一个选项卡栏中的表视图控制器)..

编辑2 : 这段代码是否很耗时 [窗口addSubview:tabBarController.view]; 当我的闪屏运行时,如何在后台执行此过程。

i have a tabbar application. here is my code

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[application setStatusBarHidden:YES animated:NO];
[self showSplashView];
}
- (void)showSplashView {
//If i don't use black view it displays white screen thats look so bad...
   UIView* blackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
blackView.backgroundColor = [UIColor blackColor];
[window addSubview:blackView]; // sends [blackView retain]
[blackView release];

splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    splashView.image = [UIImage imageNamed:@"MyImage.png"];
    [window addSubview:splashView];
    [window bringSubviewToFront:splashView];
    [UIView beginAnimations:nil context:nil ];
[UIView setAnimationDelay:5.0];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
   [UIView setAnimationDelegate:self];
   [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:) ];
   splashView.alpha = 0.0;
   splashView.frame = CGRectMake(-60, -60, 440, 600);

   [UIView commitAnimations];

  }
  - (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
UIView* blackView = [[window subviews] objectAtIndex:0];
    [blackView removeFromSuperview];
    [splashView removeFromSuperview];
    [splashView release];
[window addSubview:tabBarController.view];
[window makeKeyWindow];
 }

so my problem is when my application starts first it displays black screen ,after few second it displays my splash image. when splash screen animation finishes again it displays black screen and after few second it displays my view controller.i dont know why it happens.i hope my question is clear.
thanks
EDIT
My expected behavior is as soon as app start it should display my splash screen instead black screen and as soon as splash animation finish it should display my first view controller(which is table view controller with in first tabbar)..

EDIT 2 :
is it something time consuming in this code
[window addSubview:tabBarController.view];
how do i do this process in background while my splash screen is running.

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

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

发布评论

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

评论(1

天荒地未老 2024-08-29 14:57:11

第一次黑屏是因为你将动画延迟设置为 5 秒。与其这样做,不如花时间准备第一个视图控制器,然后显示启动动画。然后,一旦动画完成,您就可以过渡到视图控制器。

另外,您应该有一个类似于您的第一个屏幕的 Default.png。那么你就不需要担心那个 blackView 了。如果您确实对这种启动动画感兴趣,则应该使 Default.png 看起来像动画的第一帧。

不过,我强烈建议您查看 Apple 的 HIG 文档。您确实不符合这里的最佳实践。

The first black screen is because you set the animation delay to 5 seconds. Instead of doing that, why don't you spend the time preparing the first view controller, then display the splash animation. Then you can transition to the view controller once the animation is done.

Also, you should have a Default.png that resembles your first screen. Then you wouldn't need to worry about that blackView. If you're really intent on this splash animation stuff, you should make Default.png look like the first frame of the animation.

However, I highly recommend you check out Apple's HIG document. You're really not conforming to best practices here.

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