美文网首页
iOS计算按钮的按下的时间

iOS计算按钮的按下的时间

作者: 哪有猫不吃鱼 | 来源:发表于2021-10-10 11:33 被阅读0次

按钮按下和抬起的时间差可以用

///长按开始绝对时间

@property(nonatomic,assign)CFAbsoluteTime touchTime;

///长按开始

  if(sender.state ==UIGestureRecognizerStateEnded){         ///获取结束的时间

            CFAbsoluteTime over =CFAbsoluteTimeGetCurrent() -self.touchTime;

            ///判断是否要结束

            if(over>0.4){

 ///当时间大于0.4结束 

                }

    }elseif(sender.state ==UIGestureRecognizerStateBegan){

       //开始时间

       CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();

       self.touchTime = start;

    }

//开始时间

CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();

 // 记录结束时间

NSLog(@"%f",CFAbsoluteTimeGetCurrent() - start);

相关文章

网友评论

      本文标题:iOS计算按钮的按下的时间

      本文链接:https://www.haomeiwen.com/subject/rhrholtx.html