在didFinishLaunchingWithOptions中将视图显示为闪屏 [英] Show a view as a splash screen in didFinishLaunchingWithOptions

查看:79
本文介绍了在didFinishLaunchingWithOptions中将视图显示为闪屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签栏应用程序,一旦didFinishLaunchingWithOptions方法加载标签栏控制器,我想简单地显示一个视图(启动画面)。为什么这么难?请告诉我如何加载并在下面显示一个名为SplashView.xib的Xib文件并显示它:

I have a Tab Bar Application and I want to simply display a view (splash screen) once the didFinishLaunchingWithOptions method loads up the tab bar controller. Why is this so hard? Please show me how I'd load up and show a Xib file called SplashView.xib below and display it:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the tab bar controller's view to the window and display.
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

    // Load up and show splash screen Xib here

    return YES;
}


推荐答案

我要提的第一件事在HIG中,防溅屏幕特别令人不悦。特别是那些只能让用户等待的东西。盯着他们不关心的一些标志。

First thing I'd mention is that splash screens are specifically frowned upon in the HIG. Especially ones that only serve to make the user wait & stare at some logo they don't care about.

现在咆哮已经不在了,我会假设你可能正在进行一些加载d喜欢在显示标签之前发生。

Now that rant is out of the way, I'll assume that you probably have some loading going on that you'd like to have happen before the tabs are displayed.

在这种情况下,我没有在MainWindow.xib中加载标签栏。相反,我启动了我的单一视图(使用XIB)进行加载。原因是:在您甚至可以看到启动画面之前,您将支付所有这些视图的加载费用。

In this case I don't load up a tab bar in the MainWindow.xib. Instead I launch my single view (with XIB) that does the loading. The reason is this: You'll pay for the loading of all of those views before you can even see your splash screen.

在加载数据的情况下,有时这些选项卡依赖于正在加载的数据,因此等待加载标签栏控制器更有意义。

In the case of loading data, sometimes these tabs depend on this data being loaded, so it makes more sense to wait to load up the tab bar controller.

应用程序委托最终看起来像这样:

The app delegate ends up looking like this:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    [window makeKeyAndVisible];
    [window addSubview:splashController.view];  //this assumes MainWindow.xib defines your splash screen, otherwise....

    UIViewController *splashController = [[SplashController alloc] initWithNibName:@"SplashController" bundle:nil];
    splashController.delegate = self;
    [window addSubview:splashController.view];

    //hang on to it in an ivar, remember to release in the dealloc
}

然后在启动画面控制器中,当我完成加载时,我这样做:

Then in the splash screen controller, when I'm done loading, I do this:

-(void)doneLoading {
    [self.delegate performSelector:@selector(splashScreenDidFinishLoading)];
}

当然 self.delegate 不存在,可以像这样添加:

Of course self.delegate doesn't exist, and it can be added simply like this:

//header
@property (nonatomic, assign) id delegate;

//implementation
@synthesize delegate;

然后只需确认并在app delegate上实现该方法:

Then just make sure and implement that method on the app delegate:

-(void)splashScreenDidFinishLoading {
     //load up tab bar from nib & display on window
     //dispose of splash screen controller
}

我'我在一些应用程序中使用了这种模式,并且很简单并且运行良好。你也可以选择在上面的方法中做一个漂亮的过渡动画。

I've used this pattern in a handful of apps and is simple and works well. You could also choose to do a nice transition animation in the method above.

希望这有帮助。

这篇关于在didFinishLaunchingWithOptions中将视图显示为闪屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆