gpt4 book ai didi

ios - 每 3 秒只注册一次用户的点击

转载 作者:行者123 更新时间:2023-11-29 10:35:53 24 4
gpt4 key购买 nike

您如何才能让应用每 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/

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