本文介绍了在AppDelegate中将启动画面添加到iPhone应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行xcode-4.2,该项目基于使用情节提要的ios5.

I'm running xcode-4.2 and the project is based for ios5 using storyboards.

我已经使用Apple提供的模板创建了一个单视图应用程序.在情节提要中,我删除了为我创建的视图控制器,并添加了UITabBarController.接下来,我添加了一个新类MyTabBarController,它是UITabBarController的子类.

I've created a single view application , using the template provided by Apple.In the storyboard I the removed the viewcontroller created for me and added a UITabBarController.Next I added a new class MyTabBarController which is a subclass of UITabBarController.

现在,我想在TabBar出现之前显示一个初始屏幕.因此,我可以在后台进行一些加载和计算.

Now I want to show a splashscreen before the TabBar appears. So I can do some loading and calculation in the background.

我认为AppDelegate.m将是一个不错的选择.因为那是我的rootview加载的地方?还是应该显示rootviewcontroller的启动画面(在我的情况下是MyTabBarController?)?

I thought AppDelegate.m would be a good place for this. Since that's the place where my rootview get's loaded not ? Or should a show the splashscreen from the rootviewcontroller which is MyTabBarController in my case ?

所以我创建了一个xib文件.我很惊讶您可以将.xib文件添加到ios5故事板项目中.该xib文件称为SplashView.xib,它具有一个带有图像的单一视图.

So I created a xib file. I'm surprised you can add .xib files to ios5 storyboard projects. The xib file is called SplashView.xib it has a single view with an image on it.

AppDelegate中的代码

Code in AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
_splashScreen = [[UIViewController alloc] initWithNibName:@"SplashView" bundle:nil];
//_splashScreen is defined as:@property (strong, nonatomic) UIViewController *splashScreen;

[_window.rootViewController presentModalViewController:_splashScreen animated:NO];

[self performSelector:@selector(hideSplash) withObject:nil afterDelay:2];
return YES;

}

问题是什么也没有发生.即使我将值从2更改为200.该应用程序也会启动,就好像没有启动屏幕一样.

The problem is nothing happens. Even if I change the value from 2 to 200. The application starts up as if there is no splashscreen.

您可能已经注意到,我仍在努力设计Objective-C和iPhone应用程序.我希望对我的问题有一个体面的回答,可以使这个主题更加清楚.

As you might have noticed I'm still struggling with the design of objective-c and iphone application. I hope a decent answer to my question will bring some clarity to the subject.

提前谢谢!

推荐答案

初始屏幕内置于iOS应用程序中.您所需要做的就是创建一个名为Default.png和Default@2x.png的文件(用于视网膜显示),它将在启动应用程序时用作启动屏幕.

Splash screens are built into iOS apps. All you need to do is create a file called Default.png and Default@2x.png (for retina displays) and it will work as a splash screen for when the app launches.

您还可以在应用程序info.plist中设置这些图像.

You can also set what these images will be in your apps info.plist.

这篇关于在AppDelegate中将启动画面添加到iPhone应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 14:35