Implementing a splash screen in iOS

2019-01-08 10:11发布

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.

11条回答
狗以群分
2楼-- · 2019-01-08 10:17

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];}];
查看更多
够拽才男人
3楼-- · 2019-01-08 10:17

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
查看更多
叛逆
4楼-- · 2019-01-08 10:17

You only have to add three images for iPhone, iPhone 5 and iPad named Default.png, Default-568h@2x.png and Default@2x.png. Now the clarity of the images depends on the size you are taking. You should take the standard sizes.

查看更多
霸刀☆藐视天下
5楼-- · 2019-01-08 10:19

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

查看更多
你好瞎i
6楼-- · 2019-01-08 10:21

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.

查看更多
老娘就宠你
7楼-- · 2019-01-08 10:25

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

查看更多
登录 后发表回答