iOS 从 UIButton 重置/重新启动应用程序

发布于 2024-12-04 11:30:48 字数 346 浏览 0 评论 0原文

我正在开发一个简单的 iOS 应用程序,在用户执行特定触摸操作并出现“重置”按钮后需要“重新启动”或“重置”。应用程序的工作流程是这样的:

  1. 用户按住屏幕的某个区域
  2. 用户放开屏幕并快速触摸另一个区域
  3. 他们放开屏幕并触摸下一个区域所花费的时间显示在 UILabel 中。
  4. 出现一个重置按钮,用户按下该按钮重试。

步骤 1-3 完美运行,但目前我必须“重置”应用程序的唯一方法是使用主页按钮退出,打开多任务菜单并手动关闭它并重新打开它。

我知道这必须能够完成,正如我在许多应用程序中看到的那样。我只是在开发人员文档中找不到太多帮助。

谢谢!

I have a simple iOS app that I am developing that needs to be "restarted" or "reset" after a user performs a certain touch action and a "reset" button appears. The workflow of the app goes something like this:

  1. User holds a certain area of the screen
  2. User lets go of the screen and quickly touches another area
  3. The time it took for them to let go and touch the next area is displayed in a UILabel.
  4. A reset button appears in which the user presses to try again.

Steps 1-3 work perfectly, but currently the only way I have to "reset" the app is to exit with the home button, open the multi-tasking menu and manually close it and re-open it.

I know this has to be able to be done as I 've seen it in many apps. I just can't find much help with the developer docs on it.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无所的.畏惧 2024-12-11 11:30:48

您可以通过调用 abort() 来终止应用程序。不过,杀死它后就无法启动它。

也许你可以在终止提示用户打开的应用程序之前安排本地通知再来一次。

You can kill the app with a call to abort(). There's no way to start it after you killed it, though.

Perhaps you can schedule a local notification before killing the app that prompts the user to open it again.

暗地喜欢 2024-12-11 11:30:48

您可能应该创建一个重置所有变量的方法,然后调用开始步骤 1-3 的方法。要显示该按钮,请创建一个 UIButton IBOutlet 附加到重置按钮,然后将其隐藏在 viewWillAppear 中,如下所示:

[myButton setHidden:true];

要稍后显示该按钮,请使用相同的按钮,但将值设置为 false 而不是 true。

You should probably just create a method that resets all of your variables and then calls the methods that begin steps 1-3. To have the button appear, make a UIButton IBOutlet to attach to the reset button, and then hide it in viewWillAppear like this:

[myButton setHidden:true];

To then show the button later, use the same button but set the value to false instead of true.

难以启齿的温柔 2024-12-11 11:30:48

您可以尝试从应用程序窗口中删除视图控制器并释放它,然后实例化该视图控制器的新实例并将新实例作为根视图控制器添加到窗口中。

由于我假设您的视图控制器是应用程序的大部分“设置”代码发生的地方,因此这应该可以有效地重置应用程序,而无需编写大量额外的代码。此外,能够实例化视图控制器类的新实例也是拥有它的开始点。

You could try removing your view controller from the application window and releasing it then instantiating a new instance of that view controller and adding the new instance to the window as the root view controller.

Since I'm assuming your view controller is where most of your "setup" code for your app is occurring this should effectively reset the app without having to write a lot of extra code. In addition, having the ability to instantiate a new instance of your view controller class is kinda the point of having it to begin with.

暗藏城府 2024-12-11 11:30:48

您可以让应用程序休眠指定的时间间隔。

+ (void)sleepForTimeInterval:(NSTimeInterval)ti

+ (void)sleepUntilDate:(NSDate *)aDate

方法适合您

请参阅 NSThread 类文档

You can sleep your application for specified time interval.

+ (void)sleepForTimeInterval:(NSTimeInterval)ti

or

+ (void)sleepUntilDate:(NSDate *)aDate

Methods is works for you

Please refer NSThread class Documentation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文