2013-04-25 31 views
0

我有一個的viewController我在哪裏玩用AVAudioPlayer一個聲音和一個定時器正在運行使用NSTimer 2分鐘的動畫序列正在播放使用暫停計時器,UIView的動畫和音頻的iOS

[UIView animateWithDuration:2.0 
          delay:0.0 
         options:UIViewAnimationOptionCurveLinear 
        animations:^{ 
         //Rolling the Man's tongue out 
         _cooling2ManImage.alpha = 1.0; 
         _cooling3ManImage.alpha = 0.0; 
        } 
        completion:^(BOOL boolValue){ 
         [UIView animateWithDuration:2.0 
               delay:0.0 
              options:UIViewAnimationOptionCurveLinear 
              animations:^{ 
               //showing the Arrow image and translating the arrow to the mouth 
               _cooling1ArrowImage.alpha = 1.0; 
               _cooling1ArrowImage.transform = CGAffineTransformMakeTranslation(0,-110); 
              } 
              completion:^(BOOL boolValue){ 
               [UIView animateWithDuration:1.5 
                    delay:0.0 
                    options:UIViewAnimationOptionCurveLinear 
                   animations:^{ 
                    //Hiding the arrow 
                    _cooling1ArrowImage.alpha = 0.0; 
                   } 
                   completion:^(BOOL boolValue){ 
                    _cooling1ArrowImage.transform = CGAffineTransformMakeTranslation(0,0); 
                    [UIView animateWithDuration:2.0 
                         delay:0.0 
                         options:UIViewAnimationOptionCurveLinear 
                        animations:^{ 
                         //Roll the tongue back in 
                         _cooling2ManImage.alpha = 0.0; 
                         _cooling3ManImage.alpha = 1.0; 
                        } 
                        completion:^(BOOL boolValue){ 
                         //Show the arrow and translate it 
                         [UIView animateWithDuration:2.0 
                               delay:0.0 
                              options:UIViewAnimationOptionCurveLinear 
                             animations:^{ 
                              _cooling3ArrowImage.alpha = 1.0; 
                              CGAffineTransform scale; 
                              CGAffineTransform translate; 
                              scale = CGAffineTransformMakeScale(2.5, 2.5); 
                              translate = CGAffineTransformMakeTranslation(0, 40); 
                              _cooling3ArrowImage.transform = CGAffineTransformConcat(scale, translate); 
                              _cooling3ArrowImage.alpha = 0.0; 
                             } 
                             completion:^(BOOL boolValue){ 
                              [UIView animateWithDuration:2.0 
                                    delay:0.0 
                                   options:UIViewAnimationOptionCurveLinear 
                                   animations:^{ 
                                    _cooling2ManImage.alpha = 0.0; 
                                    _cooling3ManImage.alpha = 1.0; 
                                    _cooling1ArrowImage.alpha = 0.0; 
                                    _cooling3ArrowImage.alpha = 0.0; 
                                    _cooling3ArrowImage.transform = CGAffineTransformMakeTranslation(0,0); 
                                    _cooling3ArrowImage.transform = CGAffineTransformMakeScale(1,1); 
                                    if (count <= 6) { 
                                     [self startAnimation1]; 
                                     count += 1; 
                                     NSLog(@"%i",count); 
                                    } 
                                   } 
                                   completion:nil]; 
                             }]; 
                        }]; 
                   }]; 
              }]; 
        }]; 

我以實現暫停和恢復功能,以便當用戶點擊「暫停」按鈕時,音頻,動畫和計時器暫停,當用戶點擊恢復按鈕時,它會從暫停的地方恢復。可以讓任何人知道如何才能做到這一點?

回答

1

爲AVAudioPlayer使用

[avplayerObject pause]; 
[avplayerObject play]; 

for timer: 

您可以儲存的,因爲計時器開始...當計時器啓動存儲日期在一個NSDate變量,經過的時間量。然後,當用戶切換時...使用NSDate類中的timeIntervalSinceNow方法來存儲已經過了多少時間......請注意,這將爲timeIntervalSinceNow提供負值。當用戶返回使用該值來設置適當的計時器時。

查看動畫check this one

+0

如何暫停我正在使用的UIViewAnimation? – 2013-04-25 09:31:33

+0

一旦檢查我的更新之一。 – Balu 2013-04-25 09:52:46

+0

@SRS:這對你有幫助嗎? – Balu 2013-04-25 10:20:04