首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >暂停计时器,uiview动画和音频iOS

暂停计时器,uiview动画和音频iOS
EN

Stack Overflow用户
提问于 2013-04-25 16:56:09
回答 1查看 792关注 0票数 0

我有一个viewController,我使用AVAudioPlayer播放声音,使用NSTimer计时器运行2分钟,并使用播放动画序列

代码语言:javascript
复制
 [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];
                                                                                                         }];
                                                                                    }];
                                                               }];
                                          }];
                     }];

我必须实现暂停和恢复功能,以便当用户点击“暂停”按钮,音频,动画和计时器暂停,当用户点击恢复按钮,它恢复的地方,它paused.Can任何人让我知道,我可以做到这一点?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-25 17:05:02

供AVAudioPlayer使用

代码语言:javascript
复制
[avplayerObject pause];
[avplayerObject play];

for timer:

您可以存储自计时器启动以来经过的时间量...当计时器启动时,将日期存储在NSDate变量中。然后当用户切换时...在NSDate类中使用timeIntervalSinceNow方法来存储过去了多少时间……请注意,这将为timeIntervalSinceNow提供负值。当用户返回时,使用该值设置适当的计时器。

对于视图动画check this one

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16210466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档