2009-11-02 50 views
0

嗨,大家好我想爲我的應用程序創建一個介紹圖像(淡入和淡出)。 這裏是我的代碼,但是,當我在設備上運行的應用程序,我有一個問題:iphone應用程序開始的圖像介紹

  1. 我的主要筆尖頁面已經顯示
  2. 我的圖像淡入然後淡出,然後再次消失在和淡出3次

這是我的代碼和我的附加文件。請檢查出來:

.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

哇....你爲什麼不能只使用類似的東西來改變你的圖像的阿爾法?

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

由於是viewDidLoad方法,所以似乎不奇怪顯示主筆尖。

我還喜歡利用像morion的回答中的動畫內容。即使:重複的衰落可能是由多次調用viewDidLoad引起的。通過調試或記錄進行檢查。

相關問題