iOS 从 UIButton 重置/重新启动应用程序
我正在开发一个简单的 iOS 应用程序,在用户执行特定触摸操作并出现“重置”按钮后需要“重新启动”或“重置”。应用程序的工作流程是这样的:
- 用户按住屏幕的某个区域
- 用户放开屏幕并快速触摸另一个区域
- 他们放开屏幕并触摸下一个区域所花费的时间显示在 UILabel 中。
- 出现一个重置按钮,用户按下该按钮重试。
步骤 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:
- User holds a certain area of the screen
- User lets go of the screen and quickly touches another area
- The time it took for them to let go and touch the next area is displayed in a UILabel.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以通过调用
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.
您可能应该创建一个重置所有变量的方法,然后调用开始步骤 1-3 的方法。要显示该按钮,请创建一个 UIButton IBOutlet 附加到重置按钮,然后将其隐藏在 viewWillAppear 中,如下所示:
要稍后显示该按钮,请使用相同的按钮,但将值设置为 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:
To then show the button later, use the same button but set the value to false instead of true.
您可以尝试从应用程序窗口中删除视图控制器并释放它,然后实例化该视图控制器的新实例并将新实例作为根视图控制器添加到窗口中。
由于我假设您的视图控制器是应用程序的大部分“设置”代码发生的地方,因此这应该可以有效地重置应用程序,而无需编写大量额外的代码。此外,能够实例化视图控制器类的新实例也是拥有它的开始点。
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.
您可以让应用程序休眠指定的时间间隔。
或
方法适合您
请参阅 NSThread 类文档
You can sleep your application for specified time interval.
or
Methods is works for you
Please refer NSThread class Documentation