2011-10-23 142 views
-2

我有大約30張圖片。我想要在沒有用戶干預的情況下運行這些圖像的幻燈片。主要要求是 -iOS Looping圖片幻燈片

  1. image1 fadesIn,顯示20秒,image1 fadesOut - image2 FadesIn等所有這一切都自動發生。沒有用戶干預。
  2. 此外,當我們到達最後一個圖像,image20。幻燈片將循環回第一個圖像。
  3. 此幻燈片可能還有其他元素,如UILabel。所以這只是圖像幻燈片。

我最大的問題是如何將20張圖片鏈接到這個淡入/淡出動畫?我們如何在iOS中完成這項工作?

+0

http://stackoverflow.com/questions/5618964/iphone-fading-of-images –

+0

@MattiasWadman的鏈接感謝。幻燈片可能不只是圖像。如果這是你的鏈接是完美的。如果我想要這樣顯示'UILabel'會怎麼樣?在淡出其他「標籤」或「圖片」時淡化「標籤」?已經更新了點3 –

+0

的問題然後,我可能會爲每個可能包含標籤,圖像等的「圖像」創建單獨的'UIView':s,然後使用'alpha'屬性在它們之間進行動畫處理。 –

回答

2

您可以使用包含不同UIImageView的UIView來顯示幻燈片中顯示的每個圖像,並創建一個嵌套動畫塊。事情是這樣的:

[UIView animateWithDuration:1.0 
       animations:^{ /* animations */ } 
       completion:^(BOOL finished){ [UIView animateWithDuration:1.0 
                   animations:^{ /* animations */ } 
                   completion:^(BOOL finished){ [UIView animateWithDuration:1.0 
                              animations:^{ /* animations */ } 
                              completion:^(BOOL finished){}]; }]; }]; 
1

Kirualex的代碼是非常好的,乾淨,容易實現,謝謝你。 如果有人想要通過觸摸屏幕來停止轉換,啓用自動幻燈片時,我向KASlideShow.h中添加了一個布爾屬性'addTouchStop',並將以下方法添加到了KASlideShow.m中。在主viewController裏面設置這個布爾屬性爲true。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
if (addTouchStop) { 

    [self stop]; 
} 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    if (addTouchStop) { 
    [self start]; 
} 
}