iPhone:檢測用戶自上一次屏幕觸摸以來的不活動/空閑時間是否有人實(shí)現(xiàn)了一個功能,如果用戶在某一段時間內(nèi)沒有觸摸屏幕,您就會采取特定的操作嗎?我想找出最好的辦法。UIApplication中有一個與此相關(guān)的方法:[UIApplication sharedApplication].idleTimerDisabled;如果你有這樣的東西,那就太好了:NSTimeInterval timeElapsed = [UIApplication sharedApplication].idleTimeElapsed;然后,我可以設(shè)置一個計時器,并定期檢查這個值,并在它超過閾值時采取一些操作。希望這能解釋我要找的東西。有沒有人已經(jīng)處理過這個問題,或者對你會怎么做有任何想法?謝謝。
3 回答

互換的青春
TA貢獻(xiàn)1797條經(jīng)驗 獲得超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 關(guān)注
- 735 瀏覽
添加回答
舉報
0/150
提交
取消