我們?cè)谑褂靡苿?dòng)APP項(xiàng)目時(shí),當(dāng)我們第一次打開(kāi)應(yīng)用時(shí)會(huì)出現(xiàn)引導(dǎo)頁(yè),在使用apicloud進(jìn)行開(kāi)發(fā)移動(dòng)項(xiàng)目時(shí)我們也需要考慮到怎樣實(shí)現(xiàn)引導(dǎo)頁(yè)的效果,我們可以使用UIScrollPicture模塊來(lái)實(shí)現(xiàn)。

1.引導(dǎo)頁(yè)顯示判斷
var UIScrollPicture; //輪播圖模塊對(duì)象
var UIButton; //按鈕模塊對(duì)象
var vButtonId; //按鈕模塊對(duì)象索引對(duì)象
//程序啟動(dòng)入口
apiready = function() {
//引導(dǎo)頁(yè)顯示判斷
var isFirst = api.getPrefs({
key: 'isFirst',
sync: true,
});
// isFirst=false;
if (!isFirst) {
//啟動(dòng)引導(dǎo)頁(yè)面
fnStartGuidePage();
} else {
fnStartMainPage();
}
};2.UIScrollPicture模塊引導(dǎo)頁(yè)設(shè)置
function fnStartGuidePage() {
//設(shè)置頁(yè)面默認(rèn)圖片;
var tData = [
'widget://res/guide1.jpg',
'widget://res/guide2.jpg',
'widget://res/guide3.jpg',
];
UIScrollPicture = api.require('UIScrollPicture');
UIScrollPicture.open({
rect: {
x: 0,
y: 0,
w: 'auto',
h: 'auto' //此處用'auto'是為了適應(yīng)某些機(jī)型頁(yè)面底部虛擬鍵的顯示/隱藏 切換
},
data: {
paths: tData,
},
styles: {
indicator: {
align: 'center',
color: 'rgba(255,255,255,0.4)',
activeColor: '#FFFFFF'
}
},
contentMode: 'scaleToFill',
auto: false, //禁止自動(dòng)滾動(dòng)
loop: false, //禁止循環(huán)播放
}, function(ret, err) {
if (ret) {
/*
//方法1 點(diǎn)擊末頁(yè)任意位置進(jìn)入主頁(yè)面
if('click' == ret.eventType){
if(ret.index==3){
//關(guān)閉頁(yè)面,進(jìn)入主頁(yè)面
fnStartMainPage();
}
}
*/
//方法2 點(diǎn)擊末頁(yè)按鈕進(jìn)入主頁(yè)面(使用前,需在控制臺(tái)添加UIButton模塊)
//設(shè)計(jì)思路:添加一個(gè)UIButton模塊,在UIScrollPicture頁(yè)面滑動(dòng)到末頁(yè)時(shí)顯示UIButton模塊,其余頁(yè)面隱藏按鈕模塊,在按鈕模塊添加點(diǎn)事件點(diǎn)擊模塊進(jìn)入主頁(yè)面
//添加末頁(yè)點(diǎn)擊進(jìn)入主頁(yè)面方法
if ('show' == ret.eventType) {
UIScrollPicture.addEventListener({
name: 'scroll'
}, function(ret, err) {
if (ret.status) {
if (ret.index == (tData.length - 1)) {
//顯示進(jìn)入按鈕
fnShowStartBtn();
} else {
//隱藏進(jìn)入按鈕
fnHideStartBtn();
}
}
});
}
}
});
}3.引導(dǎo)頁(yè)結(jié)束跳轉(zhuǎn)到主頁(yè)面
//啟動(dòng)程序主頁(yè)面
function fnStartMainPage() {
if (UIScrollPicture) {
//緩存App啟動(dòng)信息
api.setPrefs({
key: 'isFirst',
value: '1'
});
//關(guān)閉引導(dǎo)頁(yè)模塊
UIScrollPicture.close();
//關(guān)閉方法2使用按鈕模塊
if (UIButton) {
UIButton.close({
id: vButtonId
});
}
}
//啟動(dòng)主頁(yè)面
api.openWin({
name: 'main',
url: 'html/main.html',
bounces: false,
vScrollBarEnabled: false,
hScrollBarEnabled: false,
slidBackEnabled: false,
rect: {
x: 0,
y: 0,
w: 'auto',
h: 'auto'
}
});
} 3.1最后一頁(yè)中立即進(jìn)入按鈕功能設(shè)置
//顯示進(jìn)入APP按鈕
function fnShowStartBtn() {
if (!vButtonId && vButtonId != 0) {
//初始化按鈕模塊
UIButton = api.require('UIButton');
UIButton.open({
rect: {
x: api.winWidth / 2 - 50,
y: api.winHeight - 60,
w: 100,
h: 30
},
corner: 5,
bg: {
normal: 'rgba(255,255,255,50)',
highlight: 'rgba(255,255,255,90)',
active: 'rgba(255,255,255,90)'
},
title: {
size: 20,
normal: '立即開(kāi)啟',
highlightColor: '#000000',
activeColor: '#000adf',
normalColor: '#FFFFFF',
alignment: 'center'
},
fixed: true,
move: false
}, function(ret, err) {
if ('show' == ret.eventType) {
vButtonId = ret.id;
}
if ('click' == ret.eventType) {
//關(guān)閉引導(dǎo)頁(yè),進(jìn)入主頁(yè)面
fnStartMainPage();
}
});
} else {
//模塊已初始化過(guò),直接顯示
UIButton.show({
id: vButtonId
});
}
}
//隱藏進(jìn)入按鈕
function fnHideStartBtn() {
if (UIButton) {
UIButton.hide({
id: vButtonId
});
}
}4.清除引導(dǎo)頁(yè)狀態(tài)緩存
//清除記錄引導(dǎo)頁(yè)狀態(tài)的本地緩存數(shù)據(jù)
function fnClearCache(){
api.removePrefs({
key: 'isFirst'
});
api.toast({
msg: '引導(dǎo)頁(yè)緩存數(shù)據(jù)清除成功!',
duration: 2000,
location: 'middle'
});
}關(guān)鍵詞:



