第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

iPhone:檢測用戶自上一次屏幕觸摸以來的不活動/空閑時間

iPhone:檢測用戶自上一次屏幕觸摸以來的不活動/空閑時間

心有法竹 2019-07-15 09:33:21
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個贊

以下是我一直在尋找的答案:

讓您的應(yīng)用程序委托子類UIApplication。在實(shí)現(xiàn)文件中,重寫sendEvent:方法,如下所示:

- (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");}

其中maxIdleTime和idleTimer是實(shí)例變量。

為了使其工作,還需要修改main.m以告訴UIApplicationMain使用您的委托類(在本例中是AppDelegate)作為主體類:

int retVal = UIApplicationMain(argc, argv, @"AppDelegate", @"AppDelegate");


查看完整回答
反對 回復(fù) 2019-07-15
  • 3 回答
  • 0 關(guān)注
  • 735 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號