1

Is that possible to add UIActivityIndicator to splash screen of my app?

Iam using following code in delegate.m file and its not working for me ..

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    [NSThread sleepForTimeInterval:5.0];  //for running splash screen more time
     UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
   [self.view addSubview:spinner];
    [spinner performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.0];


    return YES;
}

Please help me

Navi
  • 1,696
  • 2
  • 17
  • 36
  • 1
    take a look this http://stackoverflow.com/questions/9400193/adding-an-activity-indicator-programmatically-to-a-view – Nitin Gohel Aug 02 '13 at 05:58
  • Never sleep a thread, use notification or delegation to communicate when the operation start or finish – Andrea Aug 02 '13 at 06:09
  • @Andrea any problem with sleep? – Navi Aug 02 '13 at 06:11
  • @Navi there is nothing inherently wrong with the sleep call. The problem is that your app cannot handle events because the run loop can't execute regularly. This is critical for the main thread in which you are calling it on. You run the risk of iOS terminating your app because of this. – Ralph Caraveo Aug 02 '13 at 06:18
  • ok i will remove that one,is there any way to do it ? – Navi Aug 02 '13 at 06:20
  • @Navi hheeheheh Ralph said all ;-) – Andrea Aug 02 '13 at 06:22
  • @Andrea please check my this question http://stackoverflow.com/questions/18009890/uialertview-not-closing-properly – Navi Aug 02 '13 at 06:23
  • @Ralph please check this question http://stackoverflow.com/questions/18009890/uialertview-not-closing-properly – Navi Aug 02 '13 at 06:23
  • @Andrea please accpt my FB request ,I like to learn more when you get free time – Navi Aug 02 '13 at 06:24
  • possible duplicate of [Show activity indicator during application launch](http://stackoverflow.com/questions/6849072/show-activity-indicator-during-application-launch) – Mike Mertsock Aug 05 '13 at 02:28

2 Answers2

3

The splash screen of your app is simply a png file that is static. You cannot add anything to it like a spinner or animation. What you can do however is once the splash screen finishes loading you can show a view that also has the same splash screen and then add the spinner to it programmatically or using interface builder. Basically from the user perspective they can't tell the difference.

I've used this technique before and it works quite nicely.

By the way, your sleep call will freeze your application momentarily. You are better off using an NSTimer so that the OS doesn't terminate your app for not responding.

Ralph Caraveo
  • 10,025
  • 7
  • 40
  • 52
  • thanks. i add a uiactivity indicator with animated as its initial state.now its working – Navi Aug 02 '13 at 06:03
2

Try this...

UIImageView *splashView; // Declare in appDelegate.h

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    splashView = [[UIImageView alloc]initWithFrame:self.window.bounds];
    if (self.window.bounds.size.height > 480)
    {
        splashView.image = [UIImage imageNamed:@"Default-568h@2x.png"];
    }
    else
    {
        splashView.image = [UIImage imageNamed:@"Default.png"];
    }

    [self.window addSubview:splashView];

   // Add your spinner here.

    return YES;
}

Hope i helped.

Chirag Pipaliya
  • 1,281
  • 12
  • 20