iPhone:检测用户自上一次屏幕触摸以来的不活动/空闲时间是否有人实现了一个功能,如果用户在某一段时间内没有触摸屏幕,您就会采取特定的操作吗?我想找出最好的办法。UIApplication中有一个与此相关的方法:[UIApplication sharedApplication].idleTimerDisabled;如果你有这样的东西,那就太好了:NSTimeInterval timeElapsed = [UIApplication sharedApplication].idleTimeElapsed;然后,我可以设置一个计时器,并定期检查这个值,并在它超过阈值时采取一些操作。希望这能解释我要找的东西。有没有人已经处理过这个问题,或者对你会怎么做有任何想法?谢谢。
3 回答
互换的青春
TA贡献1797条经验 获得超6个赞
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
// Only want to reset the timer on a Began touch or an Ended touch, to reduce the number of timer resets.
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0) {
// allTouches count only ever seems to be 1, so anyObject works here.
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan || phase == UITouchPhaseEnded)
[self resetIdleTimer];
}}- (void)resetIdleTimer {
if (idleTimer) {
[idleTimer invalidate];
[idleTimer release];
}
idleTimer = [[NSTimer scheduledTimerWithTimeInterval:maxIdleTime target:self selector:@selector(idleTimerExceeded) userInfo:
nil repeats:NO] retain];}- (void)idleTimerExceeded {
NSLog(@"idle time exceeded");}int retVal = UIApplicationMain(argc, argv, @"AppDelegate", @"AppDelegate");
- 3 回答
- 0 关注
- 761 浏览
添加回答
举报
0/150
提交
取消
