2011-10-06 55 views
1

數組我有UIViews的陣列,我用下面的代碼動畫:動畫UIViews

for (int i = 0; i<(int)viewArray.count; i++) { 
    UIView *view = [viewArray objectAtIndex:i]; 
    CALayer *layer = view.layer; 

    //animate the layer 

} 

我的問題是,是否有任何方式爲具有每動畫之間的延遲,所以,例如,它在數組中激活一個UIView並在0.2秒左右後開始下一個動畫?任何幫助將不勝感激!

回答

4

你可能想嘗試以下

float timeDelay = 0.2 
float duration = YOUR_DURATION 
for (int i = 0; i<(int)viewArray.count; i++) { 
    UIView *view = [viewArray objectAtIndex:i]; 

    //animate the layer 
    [UIView animateWithDuration:duration delay:(i+1)*timeDelay 
      options: {Check UIView Class Reference on developer.apple.com} 
      animations:^{ 
        [view.layer fantastic animation here]; 
      } completion^(BOOL finised){ 
        if(finished){ 
        //Leave blank if nothing, good practice to implement debuging here or post animation processes here (like removing a subview from a super) 
        } 
      }]; 

} 

請記住,如果你寄你的程序它可能會破壞你的動畫所以確保ü在烏拉圭回合應用的代表記得這個方法的背景:

- (void)applicationWillEnterForeground:(UIApplication *)application; 

希望它可以幫助

+0

有沒有辦法在'for'循環中定義動畫列表,然後只調用一次[UIView animateWithDuration]?該方法會更有效嗎? – jwegner

0

使用這個傢伙:

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion 

使用第二個參數。在你的循環中,調用該函數,並將每增加一個數字傳遞給該參數。

+0

謝謝你,我試過,但現在沒有動畫所有..我是新來的這一點,所以我只想澄清,我做'[自animateWithDuration稱之爲:5延遲:我.. .etc',對嗎?再次感謝! – kopproduction

+0

[UIView animate ...]另外,它用於動畫UIView屬性。不確定CALayer屬性。 – Colin