如何在iPhone中的touchesBegan和touchend事件之间找到时间? [英] how to find time between touchesBegan and touchend event in iphone?

查看:39
本文介绍了如何在iPhone中的touchesBegan和touchend事件之间找到时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个iphone游戏应用程序,我想在其中找到触摸开始和触摸结束事件之间的时间.

I am implementing one iphone game application in which I want to find out time between touch begin and touch end event.

有可能吗?

请给我建议

预先感谢

推荐答案

是可以的.这非常非常容易.

Yes this is possible. And this is very very easy.

您保存触摸开始时的当前时间(即[NSDate date]),并获取触摸结束时的当前时间与保存的开始时间之间的差值.

You save the current time (i.e. [NSDate date]) when the touch starts, and get the difference between the current time when the touch ends and the saved start time.

@interface MyViewController : UIViewController {
    NSDate *startDate;
}
@property (nonatomic, copy) NSDate *startDate;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    self.startDate = [NSDate date];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSTimeInterval ti = [[NSDate date] timeIntervalSinceDate:self.startDate];
    NSLog(@"Time: %f", ti);
}

这篇关于如何在iPhone中的touchesBegan和touchend事件之间找到时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆