2014-10-29 44 views
0

我創建了一個imageView,我想顯示一個錯誤。我使用動畫淡入/淡出圖像。這是我用動畫的代碼:UIImageView不會淡入,但出

imageView.hidden = NO; 
    imageView.alpha = 0; 

    [UIView animateWithDuration:.25 animations:^{ 
     imageView.alpha = 1; 
    } completion:^(BOOL finished) { 
     imageView.hidden = NO; 
    }]; 


    imageView.alpha = 1; 

    [UIView animateWithDuration:.25 delay:4.5 options:0 animations:^{ 
     imageView.alpha = 0; 
    } completion:^(BOOL finished) { 
     imageView.hidden = YES; 
    }]; 

所以我的形象就淡出,因爲它應該,但它不褪色的,爲什麼永遠。你有好主意嗎?

+0

你需要第一動畫之前到'hidden'屬性設置爲無,你設置後'alpha' 0 – 2014-10-29 00:46:30

+0

@BrianShamblen哦,是我這樣做,我只是沒有把它放在評論,讓我編輯這個。 – LinusGeffarth 2014-10-29 00:47:13

+0

@BrianShamblen沒有,仍然沒有工作 – LinusGeffarth 2014-10-29 00:49:40

回答

0

試試這個。我通常會在第一個動畫的完成塊中添加額外的動畫。我測試了這個,它適用於我。如果這不起作用,請檢查以確保您的imageView屬性在佈局文件中正確連接。

imageView.hidden = NO; 
imageView.alpha = 0.0f; 

[UIView animateWithDuration:0.25f animations:^{ 
    imageView.alpha = 1.0f; 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.25f delay:4.5f options:0 animations:^{ 
     imageView.alpha = 0.0f; 
    } completion:^(BOOL finished) { 
     imageView.hidden = YES; 
    }]; 
}]; 
+0

太棒了!謝謝:) 但是,你能解釋爲什麼它不符合我的方式嗎? – LinusGeffarth 2014-10-29 01:06:05

+0

另外,如果我沒有延遲的動畫,你的解決方案將無法正常工作。那麼你有另一個嗎? – LinusGeffarth 2014-10-29 01:14:29

+0

我不太清楚底下發生了什麼,但根據Apple的「視圖編程指南」,他們建議在完成塊中添加任何額外的動畫。請查看標題爲「將多個動畫鏈接在一起」的部分https://developer.apple.com/Library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html – 2014-10-29 01:14:31