Titanium視頻教程:實(shí)現(xiàn)頁面跳轉(zhuǎn)
下面為視頻內(nèi)容:
創(chuàng)建工程時(shí)不選任何模板,直接點(diǎn)擊“finish”。在自動(dòng)生成的代碼里,titanium在app.js中已經(jīng)為我們創(chuàng)建了一個(gè)***容器為tabGroup,兩個(gè)tab,其下各自有一個(gè)window,每個(gè)window也都有一個(gè)label。詳細(xì)請看我做的思維圖。而我們今天要實(shí)現(xiàn):在win1對(duì)象中使用外部鏈接的方式,鏈接到一個(gè)外部window,實(shí)際效果與默認(rèn)的win2一樣,就像html中使用外部的javascript文件一樣,把所有代碼都寫在一個(gè)文件里顯然不會(huì)是我們以后做項(xiàng)目的方式。在外部window中點(diǎn)擊一個(gè)按鈕觸發(fā)頁面跳轉(zhuǎn)事件,達(dá)到我們今天要的效果。
一、在app.js修改win1屬性
1url:'win1.js'
二、創(chuàng)建win1.js文件
varwin=Titanium.UI.currentWindow;
varbutton1=Titanium.UI.createButton({
title:'按鈕',
borderRadius:2,
textAlign:1,
top:100,
width:50,
height:50,
borderColor:'#cccccc',
backgroundColor:'#eeeeee'
});
win.add(button1);
button1.addEventListener('click',function(e){
//alert('點(diǎn)擊事件觸發(fā)')
varnewWin=Titanium.UI.createWindow({
title:'新窗口',
url:'newWin.js'
});
newWin.myvar='這是一個(gè)變量文本';
Titanium.UI.currentTab.open(newWin,{animation:true});
});
三、創(chuàng)建newWin.js文件
varwin=Titanium.UI.currentWindow;
varmyvar=win.myvar;
varlabel1=Titanium.UI.createLabel({
color:'red',
text:myvar,
font:{fontSize:20,fontFamily:'HelveticaNeue'},
textAlign:'center',
width:'auto'
});
win.add(label1);
OK!完成

該圖片為適合頁面被自動(dòng)縮小.查看大圖請點(diǎn)擊.