钛后退按钮

编程入门 行业动态 更新时间:2024-10-25 02:27:51
本文介绍了钛后退按钮-始终关闭我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的App遇到新问题,我正在使用Appcelerator Titanium进行开发. 我想锁定设备上的后退"按钮,因此当我使用该应用程序时,该应用程序不会每次都关闭.我只想在主要菜单中关闭应用程序.这是我的代码:

I have a new problem with my App, i'm using Appcelerator Titanium for development. I want to lock the Backbutton from my Device, so the App wont close everytime when i use him. I want to close the App only if i'm at the primarymenu. So this is my code:

Ti.UI.currentWindow.addEventListener('android:back',function(){ alert(Ti.App.PositionNow); if(Ti.App.PositionNow=='0') { alert('do quit'); } else if(Ti.App.PositionNow=='1') { Ti.App.multi_tableView.addEventListener('click',myfunction); var duration = 300; var setOldOpacity = Titanium.UI.createAnimation(); setOldOpacity.opacity = 1; setOldOpacity.zIndex = 1; setOldOpacity.duration = duration; var setOldBottom = Titanium.UI.createAnimation(); setOldBottom.bottom = 0; setOldBottom.duration = duration; var setOldTop = Titanium.UI.createAnimation(); setOldTop.top = 0; setOldTop.duration = duration; var animationHandler2 = function() { setOldTop.removeEventListener('complete',animationHandler2); Ti.App.multi_view_first.animate(setOldTop); Ti.App.multi_view_second.animate(setOldBottom); Ti.App.multi_tableView.animate(setOldOpacity); }; setOldTop.addEventListener('complete',animationHandler2); Ti.App.multi_view_first.animate(setOldTop); Ti.App.multi_view_second.animate(setOldBottom); Ti.App.multi_tableView.animate(setOldOpacity); alert('hallo1'); Ti.App.PositionNow = 0; } return false; });

我有一个变量,可以在菜单中的层次结构上跟踪用户的位置.因此,只有在位置为"0"时,应用程序才应关闭.

I have an variable where i track the position from the user at the hierachy from the menu. So the App should only close when the position is "0".

如果位置为"1",则应该有一个动画,这样就可以了,但是在动画过程中,应用会立即关闭.

If the position is "1", there should be an animation, so this works, but during the animation, the app closes instantly.

窗口的代码是这样的:

Ti.App.hs_win = Ti.UI.createWindow({ url: '/sites/homescreen/index.js', navBarHidden: true, fullscreen: true, modal:true, theme: "Theme.Titanium", orientationModes: [Ti.UI.PORTRAIT] });

推荐答案

您监视的android:back事件已过时.请使用androidback事件.

The event you're monitoring android:back is deprecated. Please use androidback event.

第二步是阻止事件在事件处理程序链中进一步冒泡.为此,您需要取消活动:

The second step is to stop the event bubbling further in the event handler chain. For this you need to cancel the event:

Ti.UI.currentWindow.addEventListener('androidback',function(event){ event.cancelBubble = true; }

还必须修改窗口并将exitOnClose属性设置为false

Also you have to modify your window and set exitOnClose property to false

更多推荐

钛后退按钮

本文发布于:2023-11-24 18:54:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626422.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!