2017-02-20 70 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

相关问题