在 iOS 中实现闪屏
我在 Cocoa、Objective-C 和 iOS 开发方面是个新手。
我想实现一个视图,它只是一个启动屏幕,并且在路由到主视图之前只持续很短的时间。您对我应该如何实施有什么想法吗?有教程或代码示例吗?我有一些具有多个视图,但没有一个具有计时器,可以像我想要的那样在几秒钟后重定向到另一个视图。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
请参阅 应用程序启动(默认)图像。
还应该注意的是,苹果建议不要滥用启动图像作为启动画面。
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
您可以轻松地在主视图之上但在
appDelegate
中实现您的视图。例如,如果您想要淡出到主视图的启动图像:(或似乎淡出的默认图像:只需将相同的图像放在启动屏幕和默认屏幕上)。只要它是主视图,这也为您提供了正确的方向。
只需将其添加到您的
application:(UIApplication *)application didFinishLaunchingWithOptions:
方法中即可: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:正如@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.
我知道我正在回答几乎一年前的问题,但它可能对其他人有帮助 -
我刚刚发现你可以在 XCode4 中做到这一点!这使得现在这个过程变得相当简单。
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.
其他答案都很好,但我想补充一点,对于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.
在 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.
要添加启动屏幕,只需替换所有默认图像([电子邮件受保护] ,....) 与具有相同默认名称的启动图像(对于所有硬件显示类型)。
要增加启动屏幕的持续时间,在 appDelegate 方法中
只需让主线程休眠您想要的持续时间,如下所示:
您还可以在中使用 sleep(时间间隔)
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
just sleep the main thread for the duration you want as:
you can also use sleep(time interval) in
我自己必须解决同样的问题,我想我应该发布更新。
我发现我必须在 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
您只需为 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.
要添加启动屏幕,请先在项目中添加该图像,然后将以下代码添加到
didFinishLaunching
方法中的AppDelegate
方法中To add splash screen first add that image in your project and then add the following code to your
AppDelegate
method in thedidFinishLaunching
method在 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