`

iPhone Dev Sessions: Making a Splash Screen

    博客分类:
  • ios
阅读更多

 

All too often an iPhone application’s launch sequence is an overlooked detail. The most common approach is to misuse the provided Default.png file as a splash screen. As it turns out, this detailing of an application is more than a little challenging if you want to get it right and stay within Apple’s guidelines.

The key to a smooth and professional looking launch sequence starts with knowing exactly where the application will land at startup. Some applications start at exactly the same place each and every successive launch, others attempt to preserve the application’s state and launch into the screen where the user last used the application. Keeping this in mind can change the strategy of how the launch sequence is implemented. This includes screen orientation as well as how and even if the status bar it to be displayed.

One may witness flickering of the status bar from blue, to black or from black to blue during the launch sequence. This is mainly due to the fact that there are two places to change the behavior of the status bar. One is hidden in the info.plist file, and the other is typically via code in the Application Delegate’s applicationDidFinishLaunching method. Theinfo.plist configuration is used before the main window is loaded, and the code in the Application Delegate is used during the launching of the main window. The reason one may want to utilize both styles is to take advantage of a full screen splash page, and then enable the appropriate looking status bar once the application has finished loading.

For the purpose of this example application, we will assume that the user state is preserved between executions, and we do not know exactly what the screen will look like when the user enters the application. We will therefore be implementing a full-screen splash view that will have the status bar hidden during the launch sequence. Once the splash view has disappeared, a black opaque status bar will be utilized throughout the application. It is also assumed that the application will launch in portrait mode, and that the first screen the user will see will also be in portrait mode.

Editing the Configuration File

The first order of business is to take care of the status bar. In Xcode, locate theinfo.plist file for the project. To add an additional property to the plist file, simply select one of the entries and click on the plus tab that appears to the right and select Status Bar Style from the drop down list:

 

Edit Projects plist File

There are only three different styles to choose from. Try each style out to see which one fits the needs of the application being developed. For this example we will set the style toUIStatusBarStyleDefault.

UIStatusBarStyles:
UIStatusBarStyleDefault — Gray (the default)
UIStatusBarStyleBlackTranslucent — Transparent black (specifically, black with an alpha of 0.5)
UIStatusBarStyleBlackOpaque — Opaque black

If on the other hand the desire is to hide the status bar when the application launches, then yet another property needs to be set. In this case, add the “Status Bar is initially hidden” property to the plist file and be sure to check the box next to the property.

Editing the Application Delegate code

So now that the status bar style is set, and initially hidden, how does one get the status bar to display again? You can actually turn the status bar on and off programmatically via code. This is particularly handy when the need arises to display a full screen view, such as the splash screen this application is utilizing. In the applicationDidFinishLaunchingmethod of the Application’s designated AppDelegate class, add the following line of code to make the status bar visible again:

 

- (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Override point for customization after app launch
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
}
 

 

 

Adding a Default.png Image

Surprisingly, the size of this file is not as important as the naming convention of the file. Default.png is a case sensitive PNG file. The image should be 480×320 according to Apple. Following Apple’s conventions, this image should look like the view that the user will see when the application has launched, and not the actual splash screen.

Xcode provides a mechanism to create a Default.png file from an attached device running the application. From the Organizer window, select the device, click on screenshots and click capture. To make that screenshot your application’s default image, click Save As Default Image. Even though the image that is created includes the status bar as it looked when the screen shot was captured, the iPhone OS replaces it with the current status bar when your application launches. Just to be clear, this is not a splash screen…not yet.

Long Launch Sequences to Varying Views

So far, this is what most applications will implement if they implement any sort of controlled visual experience when the application launches. If you follow Apple’s guidelines, and the image you produce is the first screen that the user will see, all is good. Except, what if the launch sequence is not as fast as the user expects? What if the application preserves state and lands on a different view based on the users last know state? Then this technique is not up to the task.

Photoshop a branded image representing the application and save it as a PNG image sized at 480×320. Do not include a status bar of any kind in the image file being created. Add this image file to the project. Now the application sort of has a splash screen, through a misused implementation of the Default.png file. To correct this, simply add an image view as a property to the App Delegates header and create it as follows:

 

splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
splashView.image = [UIImage imageNamed:@"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];

 At this point, the image view is utilizing the exact same image file that was created in Photoshop. There’s no chance of the initial view being different than the Default.png file at this point. The one remaining problem is the timing of when to remove the image view from the subview. This can be handled in one of two ways…

 

 

Controlling the Duration of the Splash Screen

The first option is for those with quick startup times that just want a splash screen. In this situation, create a method to remove and release the splash view, then calling that method via a timed perform selector call as follows:

 

[self performSelector:@selector(removeSplash) withObject:nil afterDelay:1.5];

 

 The removeSplash method does just that, removes the image view from the subview and releases the object.

 

-(void)removeSplash;
{
  [splashView removeFromSuperview];
  [splashView release];
}

 

 The second method uses the same remove splash method, but relies on the built in event management to trigger when the method gets called.

 

[[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(saveClaim:)
      name:@"RemoveSplashScreen"
      object:nil];

 

 Now all that needs to be done is to post the notification from anywhere. This technique is particularly useful if the reason that the launch sequence is taking a long time has nothing to do with code that was implemented in the App Delegate.

 

[[NSNotificationCenter defaultCenter]
postNotificationName: @"RemoveSplashScreen"
object: nil];
 

 This technique can be employed from anywhere within the application. Removing the observer after the fact may avoid crashes if there is an opportunity for this notification to be fired multiple times. Releasing an object when no object it there to be released can lead to troublesome crashes to track down. The quick and dirty is to use the delay on theperformSelector call.

Conclusion

And there it is, a splash screen that conforms to Apple’s guidelines. No hidden APIs, no hacks, no special sauce. A simple, straight forward approach to making the initial interaction with the user as pleasant as possible.

转自:http://gigaom.com/apple/iphone-dev-sessions-making-a-splash-screen/

分享到:
评论

相关推荐

    sessions:Web服务的常规会话模块

    届会Web服务的常规会话模块特征异步/等待简单的自定义存储将值存储在基于serde_json的例子sessions = { version = " 0.1 " , features = [ " memory " ] } use std :: sync :: Arc;use sessions :: * ;let config = ...

    sessions:用于会话管理的Gin中间件

    会话 用于会话管理的Gin中间件,具有多后端支持:用法开始使用它下载并安装: $ go get github.com/gin-contrib/sessions 将其导入您的代码中: import "github.com/gin-contrib/sessions"基本范例单节package main...

    gin-sessions:Gin 的会话中间件

    store := sessions . NewCookieStore ([] byte ( "secret123" )) g . Use ( sessions . Middleware ( "my_session" , store )) g . GET ( "/set" , func ( c * gin. Context ){ session := sessions . Get ( c

    OSC19-Linux-Workshop-Sessions:所有以.md和.pdf格式的OSC'19研讨会。

    OSC19-Linux-Workshop-Sessions:所有以.md和.pdf格式的OSC'19研讨会。

    weekly_sessions:每周会话中使用的文件

    在IT行业中,"weekly_sessions"通常指的是某个项目或系统中记录用户周度活动或会话的数据集合。这个压缩包文件“weekly_sessions-master”可能包含了一系列与用户行为分析、数据分析或者性能监控相关的数据文件。让...

    cookie-sessions:用于Connect的基于cookie的安全会话中间件

    会话数据存储在“会话”属性中的请求对象上: var connect = require('connect'), sessions = require('cookie-sessions');Connect.createServer( sessions({secret: '123abc'}), function(req, res, next){ req....

    TF_Training_Sessions:TF培训课程笔记本

    **标题解析:** "TF_Training_Sessions:TF培训课程笔记本" 暗示这是一个关于TensorFlow训练课程的集合,其中包含一系列的教程或实践项目。"TF"是TensorFlow的缩写,这是一个广泛使用的开源机器学习框架,由Google...

    sessions:会话类型解释器实现

    会议会话类型解释器实现。 main.go 是样板代码,现在等待解析器的未来实现。 expr.y 是一种玩具示例语言的 goyacc 实现,可以作为解析器未来实现的基础。 在这一点上,大多是废代码。 会话程序的有趣代码在escapes....

    sessions:提供会话服务的Martini处理程序

    store := sessions . NewCookieStore ([] byte ( "secret123" )) m . Use ( sessions . Sessions ( "my_session" , store )) m . Get ( "/set" , func ( session sessions. Session ) string { session . Set ...

    django-dynamodb-sessions:亚马逊DynamoDB的Django会话后端

    django-dynamodb-sessions 信息: 该软件包包含一个简单的Django会话后端,该后端使用Amazon的进行数据存储。 作者: 格雷格·泰勒(Greg Taylor) 地位: 稳定但未维护(如果有兴趣维护,请打开一个问题!) ...

    ASAv 10 vmware - Activated.rar

    UC Phone Proxy Sessions : 2 perpetual Total UC Proxy Sessions : 2 perpetual Botnet Traffic Filter : Enabled perpetual Intercompany Media Engine : Disabled perpetual Cluster : Disabled perpetual

    go-sessions:Go编程语言的会话管理器。 同时支持nethttp和fasthttp

    sess := sessions . Start ( http . ResponseWriter , * http . Request ) sess . ID () string Get ( string ) interface {} HasFlash () bool GetFlash ( string ) interface {} GetFlashString ( string ) ...

    sessions:Goji 的简单服务器端会话

    MemoryStore {}var Sessions = sessions . NewSessionOptions ( secret , & inMemorySessionStore ) 使用Redis(使用fzzy/radix): var redisSessionStore = sessions . NewRedisStore ( "tcp" , "localhost:6379...

    exercise-sessions:小运动

    会话练习 介绍 会话重建,也称为会话化,是一... 计算的访问会话必须写入名为sessions.csv的文件中,文件中的每一行必须具有以下格式: IP_ADDRESS,SESSION_START,SESSION_END 在哪里: IP_ADDRESS是客户端的 IP 地

    Git-GitHub-Sessions:教新手Git,GitHub以及如何制作PR

    本教程“Git-GitHub-Sessions”旨在引导新手掌握Git的基本操作,并学会在GitHub上进行协作,特别是如何创建Pull Request (PR)。 Git是一种分布式版本控制系统,它允许开发者追踪代码更改、协同工作,并在多个版本...

    django-user-sessions:使用外键将Django会话扩展回用户,从而允许枚举所有用户的会话

    for session in user_sessions: session.expire() session.save() ``` 总之,`django-user-sessions`为Django提供了强大的会话管理功能,它增强了对用户会话的控制,使开发者能够更好地管理和监控用户的行为。这...

    WebOps-Sessions:进行会议的演讲

    在这个主题下,“WebOps-Sessions”可能是一系列关于如何在WebOps环境下进行有效演讲的讨论或教程。在进行会议演讲时,尤其在IT领域,了解JavaScript这一重要的前端编程语言是非常关键的,因为它在构建交互式和动态...

    fs_sessions:提供类似会话的文件管理的LKM

    系统还将一些统计信息提供到/ sys / kernel / session-module目录中,用户可以在其中: *See the number of total open sessions*See the number of sessions per-process and per-file*See and change the path ...

    Breakout-sessions:将存储突破会话的地方!

    在IT领域,"Breakout-sessions"通常指的是在会议、研讨会或培训中,参与者分成小组进行深入讨论或实践活动的部分。这种形式有助于增强参与者的互动性和深度学习。在本例中,"Breakout-sessions"可能是指一个项目或...

    mongoose-express-sessions:使用Mongoose进行Express会话存储

    const StoreSession = require ( "mongoose-express-sessions" ) ( session ) mongoose . connect ( ) app . use ( session ( { secret : 's3cr37' , cookie : { maxAge : 1000 * 60 * 60 * 24 * 7 } , store : ...

Global site tag (gtag.js) - Google Analytics