0
在学习Appcelerator Titanium时,我正在构建一个以包含2个标签的Window开始的应用程序。两个标签(onclick)应该打开2个不同的Windows(每个包含tabgroups)。钛设计建议
所以,在我app.js
我:
Window = require('ui/handheld/ApplicationWindow');
我
ApplicationWindow
功能
和:
var window1 = Ti.UI.createWindow({
backgroundColor:'#ffffff'
});
var label = Ti.UI.createLabel({ text: "Open first Window", top:10 });
window1.add(label);
var label2 = Ti.UI.createLabel({ text: "Open second Window", top:50 });
window1.add(label2);
var window2 = Titanium.UI.createWindow({url:"A.js",backgroundColor:'#00ff00'});
var window3 = Titanium.UI.createWindow({url:"B.js",backgroundColor:'#ff0000'});
label.addEventListener("click", function(e) {
var t = Ti.UI.iPhone.AnimationStyle.CURL_UP;
window1.animate({view:window2,transition:t},function(){window2.open();});
});
label2.addEventListener("click", function(e) {
var t = Ti.UI.iPhone.AnimationStyle.CURL_UP;
window1.animate({view:window3,transition:t},function(){window3.open();});
});
return window1;
第一个问题是:这是一个好的设计?它可以改进吗?怎么样?
第二个问题是:有没有办法显示我在转换结束前打开的页面?目前看来,A.js和B.js中包含的JS仅在动画停止时执行。
谢谢,任何帮助,欢迎和遗憾的新手问题。
[编辑]这是Ch4rAss的评论后,我当前的代码:
function ApplicationWindow() {
var root = Ti.UI.createWindow({
backgroundColor:'#ffffff'
});
var label = Ti.UI.createLabel({ text: "Open first Window", top:10 });
root.add(label);
var label2 = Ti.UI.createLabel({ text: "Open second Window", top:50 });
root.add(label2);
var win2 = require('ui/handheld/Win2');
var win3 = require('ui/handheld/Win3');
label.addEventListener("click", function(e) {
var t = Ti.UI.iPhone.AnimationStyle.CURL_UP;
win2.open({transition:t});
});
label2.addEventListener("click", function(e) {
var t = Ti.UI.iPhone.AnimationStyle.CURL_UP;
win3.open({transition:t});
});
return root;
}
module.exports = ApplicationWindow;
和:
function Win2(){
/* You can (of course) do more than this */
return Ti.UI.createWindow({backgroundColor:'#00ff00'});
}
module.exports = Win2;
这不适合我。我改了一点你的代码,W2中的函数W2变成了:'function Win2(){return Ti.UI.createWindow({backgroundColor:'#00ff00'});} module.exports = Win2;'。调用代码与您的代码很相似,但是当我点击时我收到一个错误。我的代码:'var win2 = require('ui/handheld/W2'); label.addEventListener(“click”,function(e){var t = Ti.UI.iPhone.AnimationStyle.CURL_UP; win2.open({transition :t});});'错误:行= 30; message =“'undefined'不是函数(评估'win2.open({transition:t})')”; name = TypeError; sourceId = 208669216; – ContentiousMaximus
我编辑了问题主体以显示我当前的代码! – ContentiousMaximus
也许我是未知的,但我等待我们的评论:我必须以这种方式实例化赢:var Win2 = require('ui/handheld/Win2'); var win2 = new Win2()。然后,win.open(...)... – ContentiousMaximus