如何在iOS中检测自上次触摸特定viewcontroller以来的用户不活动?
当用户在3秒钟内不触摸特定屏幕时,我需要在视图控制器中执行特定操作如何在iOS中检测自上次触摸特定viewcontroller以来的用户不活动?,ios,cocoa-touch,uikit,user-interaction,Ios,Cocoa Touch,Uikit,User Interaction,当用户在3秒钟内不触摸特定屏幕时,我需要在视图控制器中执行特定操作 如何在iOS中实现这一点?覆盖视图的触碰开始方法,并在触碰时重置计时器 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.timer invalidate]; self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@s
如何在iOS中实现这一点?覆盖视图的触碰开始方法,并在触碰时重置计时器
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.timer invalidate];
self.timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(inactivityTimerFired) userInfo:nil repeats:NO];
[super touchesBegan:touches withEvent:event];
}
如果需要,可以将视图控制器作为目标,而不是self
NSTimer
属性/ivar添加到视图控制器触摸开始:
)3.0
s的间隔启动计时器以调用函数nil
如果我点击或触摸标签或表格视图,它就不起作用了?可能是因为它们有
userInteractionEnabled=NO
@jeffamaphone我想你的意思是userInteractionEnabled=YES
,如果启用了用户交互,该对象将拦截触摸