您如何才能让应用每 3 秒记录一次用户的点击。例如:用户点击屏幕后,应用程序将不会注册或识别任何更多的点击,直到 3 秒过去,然后重复此操作。这将是通过尽可能快地点击来停止发送垃圾邮件。我阅读了手势识别器,但没有看到如何使用它。
最佳答案
使用属性跟踪用户最后一次点击屏幕的时间:
@interface GameScene()
@property NSTimeInterval lastTouch;
@end
比较当前和上次点击的时间差
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
// Check time since the last touch event
if (touch.timestamp-_lastTouch >= 3) {
// Allow touch
NSLog(@"greater than or equal to 3 seconds");
}
else {
// Ignore touch
NSLog(@"Seconds since last touch %g",touch.timestamp-_lastTouch);
}
// Store timestamp
_lastTouch = touch.timestamp;
}
关于ios - 每 3 秒只注册一次用户的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27143972/