2011-06-05 181 views
0

我做了這件事。除了向我自己演示之外,它沒有任何其他用途。實質上,我正在移動一個視圖,在循環中圍繞屏幕創建。問題在於它不會一直等到它完成一個動畫才能啓動另一個動畫,因此視圖會繞過前兩個並在for循環完成後最後一個toastRect結束,並且它不會在那。在繼續下一步之前,如何強制代碼完成每個動畫?如何停止執行FOR循環,直到代碼完成

int i; 
    for (i=0; i < 100; i++) { 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:9]; 
     toast.view.frame = toastRect1; 
     [UIView commitAnimations]; 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:9]; 
     toast.view.frame = toastRect2; 
     [UIView commitAnimations]; 

     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:9]; 
     toast.view.frame = toastRect; 
     [UIView commitAnimations]; 
     NSLog(@"%d",i); 

    } 

} 

回答