Loading Image

Discussion in 'iOS Programming' started by Futhark, Aug 25, 2011.

  1. Futhark macrumors 65816

    Futhark

    Joined:
    Jun 12, 2011
    Location:
    Northern Ireland
    #1
    I've just started working with objective-c and Xcode so I've a lot of learning and probably questions ahead of me :)

    My first question is this, I have a loading image that comes up before my app starts, unfortunately it is there for less than a second so you have barely time to see the image and read the text. How can I lengthen the time it stays on screen for?

    Many Thanks in advance



    ---
    I am here: http://maps.google.com/maps?ll=54.846420,-6.297348
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    You can't directly control the time for which that first image is displayed. It is just while the app is loading. Once the app has loaded, the app's first view is put on the screen in it's place. So you'll probably need to make your app's view be a view will that image in it, then use an NSTimer to trigger code that moves the app from the image view to an actual functional view.

    BTW Making a user wait to use your app is bad UX. The whole point of that first image is to give the illusion of instant-on apps.
     
  3. Shawnpk macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #3
    You can use: [NSThread sleepForTimeInterval: 3.0], where 3.0 is the amount of time you want the splash screen to show. But as jiminaus said, showing the splash screen for longer than necessary can be very frustrating for the user. Also, putting a thread to sleep is not the safest thing to do.
     
  4. Futhark thread starter macrumors 65816

    Futhark

    Joined:
    Jun 12, 2011
    Location:
    Northern Ireland
  5. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #5
    Out of curiosity, where would you put that?
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    Don't sleep your threads, that's not the right approach my opinion.
    Rather do something like this ->


    Code:
    
    -(void)fadeOut:(UIView*)viewToDissolve withDuration:(NSTimeInterval)duration   andWait:(NSTimeInterval)wait
    {
    	[UIView beginAnimations: @"Fade Out" context:nil];
    	
    	// wait for time before begin
    	[UIView setAnimationDelay:wait];
    	
    	// druation of animation
    	[UIView setAnimationDuration:duration];
    	viewToDissolve.alpha = 0.0;
    	[UIView commitAnimations];
    }
    
    -(void)fadeIn:(UIView*)viewToFadeIn withDuration:(NSTimeInterval)duration 	  andWait:(NSTimeInterval)wait
    {
    	[UIView beginAnimations: @"Fade In" context:nil];
    	
    	// wait for time before begin
    	[UIView setAnimationDelay:wait];
        
        // druation of animation
    	[UIView setAnimationDuration:duration];
    	viewToFadeIn.alpha = 1;
    	[UIView commitAnimations];
    	
    }
    
    /**
     Fade in from fade out
     */
    -(void) fadeInFromFadeOut: (UIView*)viewToFadeIn withDuration:(NSTimeInterval)duration
    {
    	viewToFadeIn.hidden=NO;
        
    	[self fadeOut:viewToFadeIn withDuration:1 andWait:0];
    	[self fadeIn:viewToFadeIn withDuration:duration andWait:0];
    
    }

    Put that in a .M file.
    Then just in the viewDidload, call this ->

    Code:
        [self fadeInFromFadeOut:logo1 withDuration:4];	
        [self fadeInFromFadeOut:logo2 withDuration:4];	
        [self fadeInFromFadeOut:logo3 withDuration:4];
    
    logo1,logo2,logo3 are UIImageViews (which inherits from UIView), so you can use those in the methods :)
     
  7. Shawnpk macrumors 6502

    Joined:
    Jan 13, 2011
    Location:
    Los Angeles, CA
    #7
    You put it in the application: didFinishLaunchingWithOptions: method of your AppDelegate.
     
  8. North Bronson macrumors 6502

    Joined:
    Oct 31, 2007
    Location:
    San José
    #8
    I am not sure that's the best approach. Set a flag in application:didFinishLaunchingWithOptions: and then start the animation in applicationDidBecomeActive: if the flag is on.
     

Share This Page