views:

1013

answers:

1

Hey mates,

I am really trying to do my best but I can't really find out what's going wrong in my code. I made a lot of search but I guess I just can't understand some objective c basics ;)

My first question is related to the code below :

[window addSubview:tabBarController.view];

UIImage *image = [UIImage imageNamed:@"lol.png"];
UIImageView *defaultImage = [[UIImageView alloc] initWithImage:image];

Does it make a difference doing this :

[window addSubview:defaultImage];

or this :

[tabBarController.view addSubview:defaultImage];

My second question is about creating a splash screen. I tried to do it by myself but I just can't find out what's not working (we're in appDelegate) :

[window addSubview:tabBarController.view];

UIImage *image = [UIImage imageNamed:@"lol.png"];
UIImageView *defaultImage = [[UIImageView alloc] initWithImage:image]; 

[window addSubview:defaultImage];
[window makeKeyAndVisible]; //makes the window visible right ?

UIImage *image2 = [UIImage imageNamed:@"lol2.png"];
UIImageView *pubImage = [[UIImageView alloc] initWithImage:image2];

[UIView setAnimationDelegate:self];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES]; //not sure about the forView:window ...

[defaultImage removeFromSuperview];
[window addSubview:pubImage];

[UIView commitAnimations];

Hmm, I guess since I called "makekeyandvisible" window should be visible and animation should be showed to users ...

Well, I am missing a step as it doesn't work :D.

Help welcome,

Gauthier.

+2  A: 

If you add an image to your project named "Default.png" it will act as a splash screen.

Forcing your user to look at a screen any longer than necessary is typically considered bad.

If you do want to add one anyways using addSubview: should work fine, if you'd like animation you may want to look into CATransitions instead of the UIView animations.

Adding the splash screen to the window or the main view controller should appear the same to the user.

Edit: Try this snippet -- you'll need to #include <QuartzCore/QuartzCore.h> and add the QuartzCore framework

// Using a CATransition
    CATransition* transition = [CATransition animation];
    transition.delegate = self; // if you set this, implement the method below
    transition.duration = 0.3;
    transition.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
    transition.type = kCATransitionMoveIn;
    transition.subtype = kCATransitionFromRight;
    [self.view.layer addAnimation: transition forKey: nil];
    [self.view addSubview: theNewView];

Add this if you need to do something when the transition is finished:

#pragma mark -
#pragma mark CAAnimation Delegate Methods
- (void)animationDidStop: (CAAnimation*)theAnimation finished: (BOOL)flag
{
    // Whatever you need to do when the animation is done.
}
jessecurry
Thank you for your answer but I am actually willing to know what is going wrong with this ;) I mean, for me, this code should work just fine so I would like to improve my skills by understanding what's wring in it !I will look at your CATransitions when I get some free time, cheers for that !
gotye
I think I might have a solution ... is this flip effect supposed to work on the simulator ?!?
gotye
What behavior are you seeing? Is the image showing up at all? Is it only the animation that's not working? Or is nothing showing up?
jessecurry
Well i just get the pubImage ... no animation, no track of defaultImage ...
gotye
try the code I posted to get some animations, search the documentation for kCATransition to see all of the types available.
jessecurry
It worked perfectly ;) But the thing is that I wanted a flip animation, which is currently not possible with CATransition ...
gotye
I just made it work by using a NSTimer object ... who knows why it is working as I kept the code all the same but it works :D
gotye
I tried to do the same thing and was done by NSTimer. But I am still wondering how to do it without a timer
Mickey Shine