0

m ファイルで宣言された変数。

BOOL isFirstTime;

再生ボタンが初めて押された場合は、一時停止ボタンに切り替えて機能をチェックしisFirstTime、タイマーを開始してdisplayviewsActionメソッドを実行し、一時停止ボタンが再開されて再生された場合は、機能を再度チェックする必要がありますisFirstTimeまたは 2 回目で、ヒットが 2 回目の場合は、タイマーを再開する必要があります。

-(void)playpauseAction:(id)sender {
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];
  [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(AfterOneSecondsFuction) userInfo:nil repeats:YES];
        }         
}
-(void)pauseTimer{
pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];
previousFireDate = [[timer fireDate] retain];
[timer setFireDate:[NSDate distantFuture]];
}
 -(void)resumeTimer{
float pauseTime = -1*[pauseStart timeIntervalSinceNow];
[timer setFireDate:[previousFireDate initWithTimeInterval:pauseTime sinceDate:previousFireDate]];
[pauseStart release];
[previousFireDate release];    
}
-(void)AfterOneSecondsFuction
{
if(!isFirstTime)
{
 isFirstTime=YES;
 return;
 self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                                  target:self
                                                selector:@selector(displayviewsAction:)
                                                userInfo:nil
                                                repeats:NO];

} else if (!isFirstTime){
  isFirstTime=NO;
  return;
  [self resumeTimer]; 

     }
}    

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

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

再生が最初に押されたときは、一時停止ボタンにトグルするだけで、機能をチェックしているisFirstTimeかどうかを確認せず、タイマーを開始せず、displayviewsaction を実行しているように見えます。

誰かがなぜそれが起こっていないのか、何が間違っているのかを知ることができれば.

手伝ってくれてありがとう。

4

1 に答える 1

0
BOOL isFirstTime

//Somewhere where the object is set up, isFirstTime should be set to YES


- (void)playpauseAction:(id)sender {

//When the button is pressed

if(isFirstTime) {

//Load the sound file
//Start playing the sound
//Start view controller timers
//Change the button image to paused
isFirstTime = FALSE;

}

else {

//The button has already been pressed

if ([audioPlayer isPlaying]) {

//If the sound is playing

//Stop playing the sound
//Stop view controller timers
//Change the button image to playing

}

else {

//Resume playing the sound
//Start view controller timers
//Change the button image to paused

}

}


}
于 2012-06-17T18:01:12.643 に答える