zoukankan      html  css  js  c++  java
  • iOS 计时器暂停和开始 防止重复点击

    -(IBAction)btnClick{
        [self starTimer];//开始计时
        //[self stopTimer];
    }
    
    -(NSTimer*)timer{
        if (!_timer) {
            _timer =[NSTimer scheduledTimerWithTimeInterval:5  target:self  selector:@selector(beginChange) userInfo:nil  repeats:YES];
        }
        return _timer;
    }
    
    //暂停定时器(只是暂停,并没有销毁timer)
    -(void)pauseTimer{
        [self.timer setFireDate:[NSDate distantFuture]];
    }
    //继续计时
    -(void)continueTimer{
        [self.timer setFireDate:[NSDate distantPast]];
    }
    
    //开始计时
    -(void)startimer{
        [self.timer fire];
    }
    //暂停并销毁
    -(void)stopTimer{
        [self.timer invalidate];
        self.timer = nil;
    }
    
    //开启定时器
    -(void)starTimer{
        [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(timerStar) object:nil];
        [self performSelector:@selector(timerStar) withObject:nil afterDelay:1];
    }
    

      

  • 相关阅读:
    mysql 常用语句
    easyui 时间格式化
    sql学习
    Java基础知识
    windows部署环境(laravel项目)
    gradle spring boot构建项目
    linux mysql操作
    composer
    linux常用命令
    mongodb使用手册
  • 原文地址:https://www.cnblogs.com/mapanguan/p/5853964.html
Copyright © 2011-2022 走看看