在 iOS 中实现启动画面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4980610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 18:52:51  来源:igfitidea点击:

Implementing a splash screen in iOS

objective-ciossplash-screenmultiple-views

提问by Patrice Cote

I'm quite a newbie in Cocoa, Objective-C and iOS development.

我是 Cocoa、Objective-C 和 iOS 开发的新手。

I'd like to implement a View that is just a splash screen and only last for a short time before routing to the main view. Do you have any idea on how I should implement that ? Any tutorials or code samples ? I have some with multiple views, but none with a timer to redirect to another one after a few seconds like I want to do.

我想实现一个视图,它只是一个启动画面,并且在路由到主视图之前只持续很短的时间。你知道我应该如何实施吗?任何教程或代码示例?我有一些有多个视图,但没有一个定时器像我想做的那样在几秒钟后重定向到另一个视图。

采纳答案by Espresso

See App Launch (Default) Imagesunder the iOS Application Programming Guide.

请参阅iOS 应用程序编程指南下的应用启动(默认)图像

It should also be noted Apple advised NOT abusing the launch image as a splash screen. Apple HIG

还应该注意的是,Apple 建议不要滥用启动图像作为启动画面。 苹果高

回答by NightCoder

You can easily implement your view on top of the main view but in your appDelegate. For example, if you want a splash image that fades out to the main view: (or a default image that seems to fade out: just put the same image on the splash screen and the default screen). This gives you also the right orientation as long as it is the main view's.

您可以轻松地在主视图之上实现您的视图,但在您的appDelegate. 例如,如果您想要一个淡出到主视图的初始图像:(或一个似乎淡出的默认图像:只需将相同的图像放在初始屏幕和默认屏幕上)。只要它是主视图,这也会为您提供正确的方向。

Just add it in your application:(UIApplication *)application didFinishLaunchingWithOptions:method:

只需将其添加到您的application:(UIApplication *)application didFinishLaunchingWithOptions:方法中:

 UIImageView*imageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"your_default_image_or_another.png"]];
[[firstViewController view] addSubview:imageView];
[[firstViewController view] bringSubviewToFront:imageView];

// as usual
[self.window makeKeyAndVisible];

//now fade out splash image
[UIView transitionWithView:self.window duration:1.0f options:UIViewAnimationOptionTransitionNone animations:^(void){imageView.alpha=0.0f;} completion:^(BOOL finished){[imageView removeFromSuperview];}];

回答by Waqas Raja

As @Espresso posted link, I just wants to explain it to you.

正如@Espresso 发布的链接,我只是想向您解释一下。

If you just place an image named Default.pnginside your project then it will be used for splash screen. However you can use different image name by explicitly specifying it in plist file.

如果您只是在项目中放置一个名为Default.png的图像,那么它将用于启动画面。但是,您可以通过在 plist 文件中明确指定来使用不同的图像名称。

回答by Bharat

I know I'm giving answer to almost one year old question, but it may help some one else-

我知道我正在回答将近一年前的问题,但它可能对其他人有所帮助-

I've just discovered that you can do this in XCode4! Which makes this a rather simple process now.

我刚刚发现你可以在 XCode4 中做到这一点!这使得现在这是一个相当简单的过程。

  1. Select your project in the navigation view
  2. under Targets select your application
  3. Select the Summary tab
  4. Scroll down and you'll see a place to add your splash images
  5. Right click on the boxes to Select File
  1. 在导航视图中选择您的项目
  2. 在目标下选择您的应用程序
  3. 选择摘要选项卡
  4. 向下滚动,您会看到一个添加启动图像的地方
  5. 右键单击框以选择文件

回答by nylund

The other answers are good but I'd like to add that for iPhone apps your Default.png should be 320x480 and for retina displays you should add [email protected] 640x960.

其他答案很好,但我想补充一点,对于 iPhone 应用程序,您的 Default.png 应该是 320x480,对于视网膜显示,您应该添加 [email protected] 640x960。

回答by Flaviu

In XCode 4, you can click on the Project Name(the parent in the hierarchy on the left).

在 XCode 4 中,您可以单击项目名称(左侧层次结构中的父项)。

Then in the Summarytab, under iPhone and iPad you will be able to select the Launch imagesfor each form the file system.

然后在摘要选项卡中,在 iPhone 和 iPad 下,您将能够为文件系统的每个表单选择启动图像

回答by HaemEternal

Having just had to fix this same problem myself, I thought I'd post an update.

刚刚不得不自己解决同样的问题,我想我会发布更新。

I found that I had to set the Supported Interface Orientations in the Info.plist before it would work correctly.

我发现我必须在 Info.plist 中设置 Supported Interface Orientations 才能正常工作。

I also found this article on iOSDeveloperTips.com to be pretty useful: Managing Multiple Launch Images

我还发现 iOSDeveloperTips.com 上的这篇文章非常有用:Managing Multiple Launch Images

回答by HaemEternal

To add splash screen just simply replace all the default images ([email protected],....) with your splash image with the same default name (for all hardware display type) . To increase the duration of your splash screen , in appDelegate method

要添加启动画面,只需将所有默认图像(如[email protected],....)替换为具有相同默认名称(适用于所有硬件显示类型)的启动图像。要增加启动画面的持续时间,请在 appDelegate 方法中

didFinishLaunchingWithOptions 

just sleep the main thread for the duration you want as:

只需在您想要的时间内睡眠主线程:

[NSThread SleepForTimeInterval:(Your time interval)];

you can also use sleep(time interval) in

您还可以在

didFinishLaunchingWithOptions

sleep(3);

回答by Ashutosh

You only have to add three images for iPhone, iPhone 5 and iPad named Default.png, [email protected] and [email protected]. Now the clarity of the images depends on the size you are taking. You should take the standard sizes.

您只需为 iPhone、iPhone 5 和 iPad 添加三个名为 Default.png、[email protected][email protected] 的图像。现在图像的清晰度取决于您拍摄的尺寸。你应该选择标准尺寸。

回答by Ashwin H

To add splash screen first add that image in your project and then add the following code to your AppDelegatemethod in the didFinishLaunchingmethod

要添加启动画面,首先在项目中添加该图像,然后将以下代码添加到AppDelegate方法中的didFinishLaunching方法中

[NSThread SleepForTimeInterval:(Time interval)];