Sam Guichelaar
Sam Guichelaar

Reputation: 457

Make an image view every time at launch

I want my splash image to fade after one second after launch.

So on top of the .xib I put an image view with the splash image, (

first the actual splash screen shows, then when the xib is loaded an image view with the same image is shown, making it look like it's the same splash screen

)

I use this code in ViewController.m to fade the image

[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.0];
[ImageLoading setAlpha:0];
[UIImageView commitAnimations];

This works, but If the user goes to another xib and later switches back, it shows the 1 second splash screen again.

I tried this in Viewcontroller.m

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[UIImageView beginAnimations:nil context:NULL];
[UIImageView setAnimationDuration:1.0];
[ImageLoading setAlpha:0];
[UIImageView commitAnimations];

return YES;

}

But apparently it's not getting called.

Is there any other way, to make this image view fade at launch?

Thanks a lot,

Upvotes: 0

Views: 106

Answers (4)

NSMutableString
NSMutableString

Reputation: 10743

You can add a sleep in the appDelegate like this

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    [NSThread sleepForTimeInterval:1];
}

Upvotes: 0

zahreelay
zahreelay

Reputation: 1742

set a property in your app delegate . eg @property(nonatomic,assign) BOOL isFirstTime;

in appdelegate's -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method, set it to NO.

Then in the viewController, check this value. If it is YES, show the animation and set it to NO. If it is NO, do nothing.

Upvotes: 1

Radu
Radu

Reputation: 3494

The simplest way to do this is to have a flag a bool value and pass it to the view controller then and check it if it is launched. and only show the splash screen if the value is false. something like

     if (!notShowSplashScreen) { 
...Your code ...
 notShowSplashScreen = TRUE
}

(default bool value is set to true so you don't have to pass it every time you show the screen)

Upvotes: 2

NSDmitry
NSDmitry

Reputation: 450

You need to do this in viewDidLoad method in your rootViewController

Upvotes: 0

Related Questions