开发者

Image Intro at iphone application starting

Hi guys I want to cre开发者_StackOverflow中文版ate 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:

  1. My main nib page has been displayed
  2. My image fades in and then fades out and then again fades in and fades out 3 times

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;
}

my sample code


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];


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜