改变场景的正确方法是什么?
当我做 LUA 时,我曾经运行 dofile("...");
来加载其他 lua 文件等。后来发现这是一种非常糟糕的做法,可能会导致应用程序崩溃。
现在我正在开发 WebOs 应用程序,我想确保在养成不良编程习惯之前正确改变场景。
目前,这就是我使用的:
label2Tap: function(inSender, event) {
Mojo.Controller.stageController.popScene();
Mojo.Controller.stageController.swapScene("LogicAndArithmetic");
},
这对于进入我的 LogicAndArithmetic 场景非常有用,这是这样做的最佳实践吗? 谢谢。
Back when I did LUA i used to run dofile("...");
to load other lua files and such. Later to find out that this is a very bad practice and can lead to applications breaks.
Now that I am on my way to developing a WebOs application, i want to make sure I am properly changing scene before i pick up bad programming habit.
At the moment this is what I use:
label2Tap: function(inSender, event) {
Mojo.Controller.stageController.popScene();
Mojo.Controller.stageController.swapScene("LogicAndArithmetic");
},
Which works great to get to my LogicAndArithmetic scene, is this the best practice to do such?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
webOS的Mojo框架中的场景模型就像一个堆栈一样工作。当应用程序启动时,您调用
pushScene
来显示您的主场景。通常,您随后会进行额外的pushScene
调用,将场景添加到顶部的堆栈中,然后当您完成这些场景时,它们会被弹出,通常是在用户执行“后退手势”时,将场景带回顶部。上一场景。最终你会回到你的主场景。swapScene
调用相当于为不同的场景调用popScene
,然后调用pushScene
。在您的情况下,您先调用popScene
,然后调用swapScene
,这相当于从堆栈中弹出两个场景,然后推回一个场景。它可能有效,因为你只有一个场景,但如果你有更多场景,它就无法正常工作。顺便说一句,你为什么与 Mojo 合作而不是 Enyo?
The scene model in the Mojo framework of webOS works like a stack. When the app starts you call
pushScene
to display your main scene. Normally, you then make additionalpushScene
calls to add scenes to the stack on top, and then when you are done with them they are popped, typically when the user performs the 'back gesture', bringing back the previous scene. Eventually you will be back at your main scene.The
swapScene
call is equivalent to callingpopScene
and thenpushScene
for a different scene. In your case you are callingpopScene
thenswapScene
, so that is the equivalent of popping two scenes from the stack and then pushing back one. It probably works because you have only one scene, but if you had more it would not work correctly.BTW, why are you working with Mojo and not Enyo?
虽然这在技术上是正确的,但很可能不是用户期望您的应用程序的行为方式。一般来说,当用户按下打开新场景的按钮时,它就会被放置在堆栈上,正如 Miguel 所说。用户希望能够返回并将场景从堆栈中弹出。这是自动发生的,您不需要监听此输入。您可以通过调用 Mojo.Controller.pushScene("sceneName"); 来完成此操作。虽然在某些应用程序中 swapScene 有意义,但您的应用程序可能可以被概念化为场景堆栈,并具有逻辑“后”场景。
我建议尝试一些现有的应用程序,以了解它们的行为方式。此外,虽然 Miguel 建议转向 Enyo,但值得注意的是,Enyo 应用程序并未正式在 webOS 2 设备(手机)上运行,而仅在触摸板上运行。可以在 webOS 2 设备上运行它们,但我确实相信它们会被从应用程序目录中拒绝。
While this is technically correct, it is most likely not how the user would expect your app to behave. In general, when a user presses a button that opens a new scene, it is placed on the stack, as Miguel said. The user will expect to be able to go back and pop the scene off of the stack. This happens automatically, you do not need to listen for this input. You do this by calling Mojo.Controller.pushScene("sceneName");. While there are some applications where swapScene makes sense, your app can probably be conceptualized as a stack of scenes, with a logical "back" scene.
I would reccommend playing around with some existing apps to get a feel for how they behave. Also, while Miguel suggested moving to Enyo, it is worth noting that Enyo apps are not officially supposed to work on webOS 2 devices (phones), only on the touchpad. It is possible to run them on webOS 2 devices, but I do believe that they will be rejected from the app catalog.