views:

248

answers:

2

hi guys i wanna create an intro image (fade in and fade out ) for my my application here is my code but ! when i run app on the device i have some problem :

1-my main nib page been displayed ! 2-my image fade in then fade out ... again fade in , fade out !! 3 times

here is my code and my attached file ! plz check it out : .h

@interface myProject : UIViewController {

    float alphaValue, imageAlphaValue;
}

UIImageView *IntroImage;
NSTimer *AlphaTimer;

@end

.m :

-(void)viewDidLoad
{
    imageAlphaValue = 0.0;
    alphaValue = 0.035;

    IntroImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    [self.view addSubview:IntroImage];
    [IntroImage setImage:[UIImage imageNamed:@"yourimagenamehere.png"]]; //use your image here
    [IntroImage setBackgroundColor:[UIColor blueColor]];
    [IntroImage setAlpha:imageAlphaValue];
    [IntroImage release];

    AlphaTimer = [NSTimer scheduledTimerWithTimeInterval:(0.05) target:self selector:@selector(setAlpha) userInfo:nil repeats:YES];
    [NSTimer scheduledTimerWithTimeInterval:(2.0) target:self selector:@selector(changeAlpha) userInfo:nil repeats:NO];
}

-(void)setAlpha
{
    imageAlphaValue = imageAlphaValue + alphaValue;
    [IntroImage setAlpha:imageAlphaValue];
}

-(void)changeAlpha
{
    alphaValue = -0.035;
}

my sample code

+2  A: 

wow.... why you cannot just use something like that to change your image's alpha?

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationDelegate:self];
[introImage setAlpha:0.0f];
[UIView commitAnimations];
Morion
+1  A: 

Seems to be not surprising that the main nib is shown, because it is the viewDidLoad method!

I'd also prefer to make use of the animation stuff like in morion's answer. Even though: The repeated fading is probably caused by viewDidLoad called more than once. Check it out with debugging or logging.

Kai