gpt4 book ai didi

ios - 从 NSDate 获取第一百秒的差异

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:08 25 4
gpt4 key购买 nike

我想得到两次触摸之间的时间差(以百分之一秒为单位)

float starttime;
float endtime;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

starttime = [[NSDate date] timeIntervalSince1970];

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

endtime = [[NSDate date] timeIntervalSince1970];

NSLog(@"starttime %f endtime %f",starttime,endtime);

float diff = endtime - starttime;


}
  1. 问题是我发现结束时间和开始时间是相同的,无论我触摸多长时间,但如果我删除 timeIntervalSince1970,则不是

  2. 有什么方法可以得到这种差异

最佳答案

我最好用

double startTime = CACurrentMediaTime();

这是相对计时的推荐方式

double starttime;
double endtime;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

startTime = CACurrentMediaTime();
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{

endtime = CACurrentMediaTime();
NSLog(@"starttime %f endtime %f",starttime,endtime);
double diff = endtime - starttime;
NSLog(@"Diff - %f", diff);
}

关于ios - 从 NSDate 获取第一百秒的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9554543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com