在 iOS 中实现闪屏

发布于 2024-10-17 06:49:24 字数 163 浏览 9 评论 0 原文

我在 Cocoa、Objective-C 和 iOS 开发方面是个新手。

我想实现一个视图,它只是一个启动屏幕,并且在路由到主视图之前只持续很短的时间。您对我应该如何实施有什么想法吗?有教程或代码示例吗?我有一些具有多个视图,但没有一个具有计时器,可以像我想要的那样在几秒钟后重定向到另一个视图。

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

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.

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

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

发布评论

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

评论(11

相权↑美人 2024-10-24 06:49:24

请参阅 应用程序启动(默认)图像

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

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

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

内心荒芜 2024-10-24 06:49:24

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

只需将其添加到您的 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];}];

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.

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

 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];}];
蓝天 2024-10-24 06:49:24

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

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

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

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

水中月 2024-10-24 06:49:24

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

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

  1. 导航视图中选择您的项目
  2. 在目标下的
  3. 选择您的应用程序选择摘要选项卡
  4. 向下滚动,您将看到一个用于添加启动图像的位置
  5. 右键单击框以选择文件

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.

  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
爱她像谁 2024-10-24 06:49:24

其他答案都很好,但我想补充一点,对于iPhone应用程序,您的Default.png应该是320x480,对于视网膜显示器,您应该添加 [电子邮件受保护] 640x960。

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.

巨坚强 2024-10-24 06:49:24

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

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

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

Then in the Summary tab, under iPhone and iPad you will be able to select the Launch images for each form the file system.

梦归所梦 2024-10-24 06:49:24

要添加启动屏幕,只需替换所有默认图像([电子邮件受保护] ,....) 与具有相同默认名称的启动图像(对于所有硬件显示类型)。
要增加启动屏幕的持续时间,在 appDelegate 方法中

didFinishLaunchingWithOptions 

只需让主线程休眠您想要的持续时间,如下所示:

[NSThread SleepForTimeInterval:(Your time interval)];

您还可以在中使用 sleep(时间间隔)

didFinishLaunchingWithOptions

sleep(3);

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

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);
情归归情 2024-10-24 06:49:24

我自己必须解决同样的问题,我想我应该发布更新。

我发现我必须在 Info.plist 中设置支持的界面方向才能正常工作。

我还发现 iOSDeveloperTips.com 上的这篇文章非常有用: 管理多个启动图像

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.

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

开始看清了 2024-10-24 06:49:24

您只需为 iPhone、iPhone 5 和 iPad 添加三个名为 Default.png 的图像,[email  ;受保护][电子邮件受保护]。现在图像的清晰度取决于您拍摄的尺寸。您应该采用标准尺寸。

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.

初见终念 2024-10-24 06:49:24

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

[NSThread SleepForTimeInterval:(Time interval)];

To add splash screen first add that image in your project and then add the following code to your AppDelegate method in the didFinishLaunching method

[NSThread SleepForTimeInterval:(Time interval)];
往事风中埋 2024-10-24 06:49:24

在 Storyboard Xcode 版本 12.5.1 (12E507) 上实现启动屏幕的最佳解决方案
只需 4 步,您的启动画面就完成了
输入图片此处描述

Best solution for implementing splash screen on Storyboard Xcode Version 12.5.1 (12E507)
in 4 steps your splash screen is done
enter image description here

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