2017-02-20 49 views
0

不確定是否有可能,但有什麼方法可以檢測到主頁按鈕上的單點觸摸。首先,我只想添加一個NSLog,如果用戶在home按鈕上觸摸一次(沒有實際按下),但我不知道在哪裏添加這個功能。 Apple允許您與主頁按鈕進行交互嗎?如何檢測和實現單擊主頁按鈕上的觸摸事件?

我看了一下應用程序的委託方法,但我看不到在單擊(觸摸)上下文中有任何工作方式。非常感謝你的幫助。

+0

當你點擊主頁按鈕,應用程序將轉到'背景'模式。您可以在AppDelegate的方法中編寫您的邏輯: - 'applicationDidEnterBackground' – pkc456

+0

Hi @ pkc456通過'點擊'我的意思是'觸摸',而不是按 - 所以單擊主頁按鈕時不點擊/按 – hinterbu

回答

1

Apple允許您與主頁按鈕進行交互嗎?

不,還沒有。沒有任何API可用於明確檢測主頁按鈕交互。
您可以依靠傳統的app delegate生命週期函數調用來執行您想要的任何邏輯。

- (void)applicationWillResignActive:(UIApplication *)application 
{ 
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
} 

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
} 

- (void)applicationWillTerminate:(UIApplication *)application 
{ 
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
} 
+0

啊。所有這些方法看起來好像與應用程序即將終止或不活動時相關,是否正確?在應用程序的正常運行中,我可以在應用程序仍處於活動狀態的任何時候檢測到主頁按鈕上的單點觸摸嗎? – hinterbu

+0

@hinterbu不,沒有主頁按鈕觸及事件API可用。應用程序無法解密設備主頁按鈕上的任何觸摸/點擊。 – ystack