如何检测和实现单击主页按钮的触摸事件?

时间:2017-02-20 20:05:58

标签: objective-c ios10 uitouch uiresponder

不确定是否可行,但有没有办法检测主页按钮上的单次触摸。首先,如果用户在主页按钮上触摸一次(没有实际按下),我只想添加一个NSLog,但我不知道在哪里添加此功能。 Apple是否允许您与主页按钮进行交互?

我查看了应用委托方法,但我无法看到在单击(触摸)上下文中如何工作。真的很感谢你的帮助。

1 个答案:

答案 0 :(得分: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:.
}