How can I display a splash screen for longer on an iPhone?

前端 未结 24 1745
滥情空心
滥情空心 2020-11-27 11:37

How can I display a splash screen for a longer period of time than the default time on an iPhone?

相关标签:
24条回答
  • 2020-11-27 12:12

    I did it pretty simply, by having my rootViewController push a modalViewController, loading from "Splash.nib" in a subclass of UIViewController I called "SplashViewController". The exact call was:

    - (void) viewDidLoad {
    SplashViewController *splashScreen = [[[SplashViewController alloc]    
            initWithNibName:@"SplashViewController" bundle:nil] autorelease];
    [self presentModalViewController:splashScreen animated:NO];
    //continue loading while MVC is over top...
    

    When you launch the app, it pops right up, like a splash screen should. Then, the SplashViewController nib is just a full-screen UIImageView with a splash png, 320x480. After a 1-second NSTimer (anything more did seem to get in the way), it fires timerFireMethod, a custom method that just calls

    [self dismissModalViewControllerAnimated:YES];
    

    Then the modal VC just slides down and away, leaving my top tableView. The nice thing is, while the MVC is up, the underlying table can continue to load due to the independent nature of modal view controllers. So, I don't think this violates the HIGs, and actually does allow for faster launching. What would you rather look at, a cute picture, or an empty default view (snore)?

    0 讨论(0)
  • 2020-11-27 12:12

    simply use sleep(time in seconds); in your applicationDidFinishedLaunching method

    0 讨论(0)
  • 2020-11-27 12:14

    There is default image (default.png) is shown when you start your app.

    So you can add a new viewcontroller which will display the that default image in the application didFinishLoading.

    So by this logic you display the default image for a bit longer.

    0 讨论(0)
  • 2020-11-27 12:15

    I needed to do this to block showing a table view until the data was loaded over the network. I used a variation of one I found here:

    http://michael.burford.net/2008/11/fading-defaultpng-when-iphone-app.html

    In the interface of your App Delegate:

    
    @interface AppDelegate : NSObject 
    {
      UIImageView *splashView;
    }
    

    In the implementation:

    
    @implementation AppDelegate
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    
    
      // After this line: [window addSubview:tabBarController.view];
    
      splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
      splashView.image = [UIImage imageNamed:@"Default.png"];
      [window addSubview:splashView];
      [window bringSubviewToFront:splashView];
    
      // Do your time consuming setup
    
      [splashView removeFromSuperview];
      [splashView release];
    }
    
    

    Make sure you have a Default.png in the resources

    0 讨论(0)
  • 2020-11-27 12:15

    Yes, the simplest way is (remember to add your 'default.png' to targets -> [yourProjectName]: launch images in 'xCode'):

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [NSThread sleepForTimeInterval:3.0];
    }
    
    0 讨论(0)
  • 2020-11-27 12:16

    The simplest way is to put your application's main thread into a sleep mode for desired period of time. Provided that "Default.png" exists in your application's bundle it will be displayed for as long as the main thread is asleep:

    
    -(void)applicationDidFinishLaunching:(UIApplication *)application {
        [NSThread sleepForTimeInterval:5];
        window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
        [window setBackgroundColor:[UIColor yellowColor]];
        [window makeKeyAndVisible];
    }
    
    

    As you are already aware, it's a horribly bad idea to do but it should work just fine...

    0 讨论(0)
提交回复
热议问题