Dav*_*eck 1 iphone cocoa objective-c
根据cocoa文档,timestampon UIEvent是"自系统启动以来的秒数".这是一个NSTimeInterval.
我想尽可能有效地生成一个等价的数字.当然,我想在UIEvent不发光的地方做这件事.:-)
好的,我做了一点挖掘,这就是我想出的:
#import <mach/mach.h>
#import <mach/mach_time.h>
+ (NSTimeInterval)timestamp
{
// get the timebase info -- different on phone and OSX
mach_timebase_info_data_t info;
mach_timebase_info(&info);
// get the time
uint64_t absTime = mach_absolute_time();
// apply the timebase info
absTime *= info.numer;
absTime /= info.denom;
// convert nanoseconds into seconds and return
return (NSTimeInterval) ((double) absTime / 1000000000.0);
}
Run Code Online (Sandbox Code Playgroud)
这似乎相当于timestampfrom UIEvent,考虑到什么mach_absolute_time()是有意义的.
| 归档时间: |
|
| 查看次数: |
1210 次 |
| 最近记录: |