Reputation: 4994
Hi guys I want to create an intro image (fade in and fade out ) for my application. Here is my code but, when I run the app on the device I have a problem:
Here is my code and my attached file. Please 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;
}
Upvotes: 0
Views: 866
Reputation: 10860
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];
Upvotes: 2
Reputation: 10775
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.
Upvotes: 1