2010-10-14 101 views
1

我在使用動畫塊時遇到困難。我試圖讓第一個動畫改變圖像的alpha值,使其閃爍,然後在10秒後消失。第一個動畫然後轉移到secondAnimation,它只對不同的圖像做同樣的事情。該過程然後無限重複。動畫塊無限循環 - iphone

我一直在工作這一段時間了,不能讓它無限重複。我遇到的另一個問題是有這個動畫過程延遲 - 以便它在20秒後開始,有足夠的時間播放音頻文件。

- (void) firstAnimation { 
      UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear; 

      [UIView animateWithDuration:1.0 delay:10.0 options:options animations:^ 
      { 
        myImage.alpha = 0.0; 
        myImage.alpha = 1.0; 

      } 

        completion:^(BOOL finished){ 

        [self secondAnimation]; 
      } 
      ]; 

    } 

感謝一如既往的任何幫助。我已經搜索了示例代碼和教程,但我發現的基本上是我在上面的代碼中做的。

回答

1

我認爲你必須在動畫塊外設置你的alpha的初始值,並且只需要在塊內部設置你想要動畫的值。

UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear; 
myImage.alpha = 0.0; 
[UIView animateWithDuration:1.0 delay:10.0 options:options animations:^ 
     { 
       myImage.alpha = 1.0; 

     } 
+0

的感謝!這很好地工作。你知道我怎麼能把它放在一個無限循環? 再次感謝 – hanumanDev 2010-10-14 13:15:28

+0

您應該能夠通過以上述方式鏈接功能來實現這一點。第一個anim調用第二個調用第一個等等。除此之外,我會建議使用NSTimer每隔X秒調用第一個動畫函數以獲得無窮大。 – Ben 2010-10-14 13:20:56

+0

好的,謝謝。也許我應該使用NSTimer,因爲我希望動畫在音頻剪輯播放後開始。 – hanumanDev 2010-10-14 13:52:59

1
animateImageWithCount:(int)aCount{ 
    if(aCount >= [imageArray count]){ 
     NSLog(@"Done all images"); 
     return; 
    } 

    UIImage *myImage = [ImageArray objectAtIndex:aCount]; 
    UIViewAnimationOptions options = UIViewAnimationOptionCurveLinear; 

    myImage.alpha = 0.0; 
    [UIView animateWithDuration:1.0 delay:10.0 options:options animations:^{ 
     myImage.alpha = 1.0; 
    } 
    completion:^(BOOL finished){ 
     [self animateImageWithCount:(aCount+1)]; 
    }]; 
} 
+0

哇。你真的救了我一段時間。我一直在尋找解決方案的時間,你的美麗。謝謝! – CoderMarkus 2012-09-01 07:11:06