0

I have a viewController where I am playing a sound using AVAudioPlayer and a timer is running for 2 minutes using NSTimer and a sequence of animation is being played using

 [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];
                                                                                                         }];
                                                                                    }];
                                                               }];
                                          }];
                     }];

I ahve to implement the pause and resume functionality so that when the user hits the "Pause" button ,the audio ,the animation and the timer pauses and when the user hits the resume button the it resumes exactly from where it paused.Can anyone let me know as how can I achieve this?

Rahul Singh
  • 1,219
  • 3
  • 13
  • 36

1 Answers1

1

for AVAudioPlayer use

[avplayerObject pause];
[avplayerObject play];

for timer:

You can store the amount of time that has passed since the timer started... When the timer starts store the date in an NSDate variable. Then when the user switches... use the method timeIntervalSinceNow in the NSDate class to store how much time has passed... note that this will give a negative value for timeIntervalSinceNow. When the user returns use that value to set an appropriate timer.

for view animations check this one

Community
  • 1
  • 1
Balu
  • 8,470
  • 2
  • 24
  • 41