简体   繁体   English

重新启动IOS中的主线程

[英]Restarting Main Thread in IOS

I have an application/game which I am adding a restart button to. 我有一个要添加重新启动按钮的应用程序/游戏。 The easiest thing for me to do this is if there was a bit of code which would release all objects created by the app running and restart the main thread (there are many of them including timers which may be running when the reset button is being pressed). 对我来说,最简单的方法是,如果有一些代码可以释放应用程序运行时创建的所有对象,然后重新启动主线程(其中许多定时器包括计时器,当按下重置按钮时它们可能正在运行) )。

Is there any such code? 有没有这样的代码?

I understand that it may be possible to run the app in a secondary thread and refresh that but I dont have any threading experience. 我了解可以在辅助线程中运行该应用程序并进行刷新,但是我没有任何线程处理经验。

can anyone help? 有人可以帮忙吗?

我唯一知道的是您可以强制杀死您的应用程序,但要做好准备,因为它会被苹果拒绝,即使您成功杀死了该应用程序,也无法重新启动它。

It is not possible to restart the main thread or anything similar. 无法重新启动主线程或类似的东西。 You're probably thinking of the wrong design. 您可能正在考虑错误的设计。 Think of it from an object oriented perspective: what you need to do is to restore the state of some objects that keep track of the state of your application. 从面向对象的角度考虑它:您需要做的是还原一些跟踪应用程序状态的对象的状态。 So say you have a Game class that has some properties like: 假设您有一个Game类,该类具有一些属性,例如:

  • level 水平
  • points

what you'd have to do is restore those to 0 (or whatever the initial value is). 您要做的就是将其恢复为0(或任何初始值)。

Hope you get the idea ;) 希望你能明白;)

没有简单的方法,如果您想重新启动游戏或关卡,则必须重新创建关卡,通过重新分配关卡变量来重绘正确的组件等,您将无法重新启动游戏。或通过重新启动线程来进行分级,

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM