简体   繁体   English

当用户单击“主页”按钮时,如何重置我的iOS应用?

[英]How do I make my iOS app reset when the user clicks the home button?

I have an animation based timer app that does not reset when I exit the app. 我有一个基于动画的计时器应用程序,退出该应用程序后不会重置。 I need to click the home button, then quit the app and re-launch it to get the timer to reset. 我需要单击“主页”按钮,然后退出应用程序并重新启动它以重置计时器。 How do I tell the app to reset when the home button is pushed? 当按下主屏幕按钮时,如何告诉应用重置?

What you are looking for is ( source ): 您正在寻找的是( 来源 ):

- (void)applicationDidBecomeActive:(UIApplication *)application

This method is called to let your application know that it moved from the inactive to active state. 调用此方法是为了让您的应用程序知道它已从非活动状态变为活动状态。 This can occur because your application was launched by the user or the system. 发生这种情况的原因是您的应用程序是由用户或系统启动的。 Applications can also return to the active state if the user chooses to ignore an interruption (such as an incoming phone call or SMS message) that sent the application temporarily to the inactive state. 如果用户选择忽略使应用程序暂时进入非活动状态的中断(例如来电或SMS消息),则应用程序也可以返回到活动状态。

You should use this method to restart any tasks that were paused (or not yet started) while the application was inactive. 您应使用此方法重新启动应用程序处于非活动状态时已暂停(或尚未启动)的所有任务。 For example, you could use it to restart timers or throttle up OpenGL ES frame rates. 例如,您可以使用它重新启动计时器或限制OpenGL ES帧速率。 If your application was previously in the background, you could also use it to refresh your application's user interface. 如果您的应用程序以前处于后台,则也可以使用它来刷新应用程序的用户界面。

OLD ANSWER: 旧答案:

In your UIApplicationDelegate , there is a delegate method: UIApplicationDelegate ,有一个委托方法:

 [– applicationDidEnterBackground:][2]

which is called when you app enter background. 当您的应用进入后台时调用。 You could stop the timer there. 您可以在那里停止计时器。

If you also want that the timer is stopped in the face of other interruptions, like an incoming call, you could use: 如果您还希望在遇到其他中断(例如来电)时停止计时器,则可以使用:

applicationWillResignActive

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当用户单击我网站上的 html 按钮时,如何将联系人保存到 Android/IOS 电话簿(联系人应用程序) - How to save a contact to Android/IOS phone book (contacts app) when a user clicks an html button on my website 用户单击“主页”按钮时如何显示退出确认对话框? - How to show exit confirm dialog when user clicks Home button? 用户按下主屏幕按钮时,如何使我的广播流应用程序继续唱歌? - How can I make my Radio Streaming Application keep singing when the user press the home button? 当用户单击“添加到主屏幕”时,是否可以向iPhone定位的Web应用程序添加其他内容? - Can I add additional content to my iPhone-targeted web app when the user clicks on “add to home screen”? iOS如何重置按钮图像? - iOS how do I reset button images? iPhone:当用户单击主页按钮时,是否可以关闭应用程序而不是在后台运行? - iPhone: Is it possible to close the app rather than run in background when user clicks Home Button? 当用户单击ios中的“更多”按钮时,如何展开UITextview - how to expand the UITextview when user clicks on “more ” Button in ios 导出图标以进行即席分发时,如何使我的图标出现在IOS PhoneGap应用程序上? - How do I make my Icon appear on my IOS PhoneGap app when I export it for adhoc distribution? 当用户点击应用中的任何链接时,如何阻止我的ios应用打开网址? - How do i stop my ios app from opening a url when user taps on any link in the app? 当用户在iOS中删除我的应用时,我可以做什么? - Can I do something when user deletes my app in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM