计算事件之间的间隔

问题描述

| 在iPhone上记录两次用户事件之间的时间的好方法是什么?即。按下Button_A和Button_B之间的时间。     

解决方法

        与使用ѭ0相比,更准确的方法是使用accurate2ѭ的
timestamp
属性。要获得
UIEvent
,请确保对目标动作方法使用两个参数的形式。
- (IBAction)buttonPressed:(UIButton *)sender event:(UIEvent *)event
{
    NSTimeInterval timestamp = event.timestamp;
    NSTimeInterval secondsSinceLastEvent = timestamp - lastTimestamp;
}
    ,        好吧,您可以根据自己的情况调整此类代码:
NSDate *start = [NSDate date];
//do some stuff
NSLog(@\"%f seconds elapsed\",[[NSDate date] timeIntervalSinceDate:start]);
例如,在Button_A动作中写入ѭ6and,在Button_B动作中写入
NSLog(@\"%f seconds elapsed\",[[NSDate date] timeIntervalSinceDate:start]);
。     ,        当按下buttonA时创建一个NSDate对象,然后每按下一次buttonB都获得从现在开始经过的时间,如下所示:
[[NSDate now] timeIntervalSince:buttonADate];
    

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...