Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 第一次运行计时器,第二次恢复计时器_Iphone - Fatal编程技术网

Iphone 第一次运行计时器,第二次恢复计时器

Iphone 第一次运行计时器,第二次恢复计时器,iphone,Iphone,m文件中声明的变量 BOOL isFirstTime; 我希望如果第一次按下播放按钮,它应该切换到暂停按钮并检查功能isFirstTime,然后它应该启动计时器并执行displayviewsAction方法,如果暂停按钮恢复播放,那么它应该再次检查功能isFirstTime或第二次,如果是第二次点击,则应恢复定时器 -(void)playpauseAction:(id)sender { if ([audioPlayer isPlaying]){ [sender setI

m文件中声明的变量

BOOL isFirstTime;
我希望如果第一次按下播放按钮,它应该切换到暂停按钮并检查功能
isFirstTime
,然后它应该启动计时器并执行
displayviewsAction
方法,如果暂停按钮恢复播放,那么它应该再次检查功能
isFirstTime
或第二次,如果是第二次点击,则应恢复定时器

-(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];
 }
看起来当第一次按下play时,它只是切换到暂停按钮,没有检查功能
isFirstTime
或否,也没有启动计时器并执行displayviewsaction

如果有人能告诉我为什么没有发生,我做错了什么


谢谢您的帮助。

我想说的是,您有一个播放按钮,按下时会切换到“暂停”按钮,播放音频文件,启动计时器,并开始以不同的时间间隔逐个加载视图控制器。现在,按下“暂停”按钮时,应该暂停计时器,以便视图控制器不会加载此外,当再次按下“暂停”按钮以继续时,它应恢复计时器并从该点开始加载视图控制器。好的,很酷,假设您只是询问如何实现该按钮,而不是视图控制器的切换方式,我已更新了答案;顺便说一句,我不确定你所说的“函数isFirstTime”是什么意思,你没有方法isFirstTime,因为你没有引用它,你是说BOOL isFirstTime,因为它是指针/iVar,不是方法。是的,它是BOOL isFirstTime作为一个变量,我以前没有使用过BOOL,以及如何将它设置为YESA BOOL,或boolean,是最原始的数据类型,为1或0表示是/否或真/假,这是iOS中的宏。所以,要回答您的问题,您所要做的就是
isFirstTime=YES
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

}

}


}