1

我不知道如何编写代码,但我希望程序跳过或跳过该语句的执行

self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                                  target:self
                                                selector:@selector(displayviewsAction:)
                                                userInfo:nil
                                                 repeats:NO];

当按下暂停以恢复播放时。

原因我希望这个原因在播放/暂停按钮中一切都很好,除非按下暂停以恢复它通过从下面的代码执行此语句开始重新加载视图控制器

self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                                  target:self
                                                selector:@selector(displayviewsAction:)
                                                userInfo:nil
                                                 repeats:NO];

我已经尝试了很多不同的方法来解决这个问题,但没有任何效果。

 if([audioPlayer isPlaying]){
    [sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
    [audioPlayer pause];
    [self pauseTimer];
}else {
    [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    [audioPlayer play];
    [self resumeTimer];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                                  target:self
                                                selector:@selector(displayviewsAction:)
                                                userInfo:nil
                                                 repeats:NO];

这就是一个接一个地加载视图控制器的方式

- (void)displayviewsAction:(id)sender
 {  
  First *firstController = [[First alloc] init];
  firstController.view.frame = CGRectMake(0, 0, 320, 480);
  CATransition *transitionAnimation = [CATransition animation];   
  [transitionAnimation setDuration:1];
  [transitionAnimation setType:kCATransitionFade];
  [transitionAnimation setTimingFunction:[CAMediaTimingFunction       functionWithName:kCAMediaTimingFunctionEaseIn]];
  [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];
  [self.view addSubview:firstController.view];
  [self.view addSubview:toolbar];
  [firstController release];
  self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];  
  }

  -(void)Second 
  {
   Second *secondController = [[Second alloc] init];
   secondController.view.frame = CGRectMake(0, 0, 320, 480);
   CATransition *transitionAnimation = [CATransition animation];
   [transitionAnimation setDuration:1];
   [transitionAnimation setType:kCATransitionReveal];
   [transitionAnimation setTimingFunction:[CAMediaTimingFunction     functionWithName:kCAMediaTimingFunctionEaseIn]];
   [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionReveal];
   [self.view addSubview:secondController.view]; 
   [self.view addSubview:toolbar];
   [secondController release];
   self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(Third) userInfo:nil repeats:NO];
    }

这是我最后一次尝试看看是否可以找到解决此问题的方法。我在这个问题上花了两个星期,但没有成功。

如果有人可以解决我的这个问题。

非常感谢您的帮助。

4

1 回答 1

1

我找到了一个有点复杂的解决方案。在您.h的文件中创建一个BOOL isFirstTime; int methodSelector;. 在您的实现文件中:

-(void)viewDidLoad
{
 isFirstTime = YES;
 methodSelector = 1;
}

并像这样更改您的代码:

if([audioPlayer isPlaying])
{
    [sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
    [audioPlayer pause];
    [self pauseTimer];
}
else
{
    [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    [audioPlayer play];
    [self resumeTimer];
switch(methodSelector)
{
 case 1:self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                              target:self
                                            selector:@selector(displayviewsAction:)
                                            userInfo:nil
                                             repeats:NO];
 break;
 case 2:self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];
 break;
 .
 .
 .


 }
}
if(isFirstTime == YES)
{
    self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                                  target:self
                                                selector:@selector(displayviewsAction:)
                                                userInfo:nil
                                                 repeats:NO];
isFirstTime  = NO;
}

相应methodSelector地在您的视图中设置更改方法。在Second方法中将其设置为 2 在Third将其设置为 3 等等。

- (void)displayviewsAction:(id)sender
 {  
  First *firstController = [[First alloc] init];
  firstController.view.frame = CGRectMake(0, 0, 320, 480);
  CATransition *transitionAnimation = [CATransition animation];   
  [transitionAnimation setDuration:1];
  [transitionAnimation setType:kCATransitionFade];
  [transitionAnimation setTimingFunction:[CAMediaTimingFunction       functionWithName:kCAMediaTimingFunctionEaseIn]];
  [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFade];
  [self.view addSubview:firstController.view];
  [self.view addSubview:toolbar];
  [firstController release];
methodSelector = 2;
  self.timer = [NSTimer scheduledTimerWithTimeInterval:23 target:self selector:@selector(Second) userInfo:nil repeats:NO];  
  }

  -(void)Second 
  {
   Second *secondController = [[Second alloc] init];
   secondController.view.frame = CGRectMake(0, 0, 320, 480);
   CATransition *transitionAnimation = [CATransition animation];
   [transitionAnimation setDuration:1];
   [transitionAnimation setType:kCATransitionReveal];
   [transitionAnimation setTimingFunction:[CAMediaTimingFunction     functionWithName:kCAMediaTimingFunctionEaseIn]];
   [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionReveal];
   [self.view addSubview:secondController.view]; 
   [self.view addSubview:toolbar];
   [secondController release];
methodSelector = 3;
   self.timer = [NSTimer scheduledTimerWithTimeInterval:27 target:self selector:@selector(Third) userInfo:nil repeats:NO];
    }

methodSelector用于暂停后调用方法。

于 2012-06-18T19:17:12.677 回答