久久无码中文字幕_日韩精品无码一本二本三_久久精品呦女暗网_欧美一级夜夜爽_久久精品国产99久久99久久久

01
2018/07

APICloud中引導(dǎo)頁的實(shí)現(xiàn)方法

發(fā)布時間:2018-07-01 18:52:50
發(fā)布者:chaobai
瀏覽量:
0

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

引導(dǎo)頁.png

1.引導(dǎo)頁顯示判斷

var UIScrollPicture; //輪播圖模塊對象
    var UIButton; //按鈕模塊對象
    var vButtonId; //按鈕模塊對象索引對象

    //程序啟動入口
    apiready = function() {
        //引導(dǎo)頁顯示判斷
        var isFirst = api.getPrefs({
            key: 'isFirst',
            sync: true,
        });
        // isFirst=false;
        if (!isFirst) {
            //啟動引導(dǎo)頁面
            fnStartGuidePage();
        } else {
            fnStartMainPage();
        }
    };

2.UIScrollPicture模塊引導(dǎo)頁設(shè)置

function fnStartGuidePage() {
        //設(shè)置頁面默認(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ī)型頁面底部虛擬鍵的顯示/隱藏 切換
            },
            data: {
                paths: tData,
            },
            styles: {
                indicator: {
                    align: 'center',
                    color: 'rgba(255,255,255,0.4)',
                    activeColor: '#FFFFFF'
                }
            },
            contentMode: 'scaleToFill',
            auto: false, //禁止自動滾動
            loop: false, //禁止循環(huán)播放
        }, function(ret, err) {
            if (ret) {
                /*
                  //方法1  點(diǎn)擊末頁任意位置進(jìn)入主頁面
                  if('click' == ret.eventType){
                     if(ret.index==3){
                       //關(guān)閉頁面,進(jìn)入主頁面
                       fnStartMainPage();
                     }
                  }
                */
                //方法2  點(diǎn)擊末頁按鈕進(jìn)入主頁面(使用前,需在控制臺添加UIButton模塊)
                //設(shè)計(jì)思路:添加一個UIButton模塊,在UIScrollPicture頁面滑動到末頁時顯示UIButton模塊,其余頁面隱藏按鈕模塊,在按鈕模塊添加點(diǎn)事件點(diǎn)擊模塊進(jìn)入主頁面
                //添加末頁點(diǎn)擊進(jìn)入主頁面方法
                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)頁結(jié)束跳轉(zhuǎn)到主頁面

//啟動程序主頁面
    function fnStartMainPage() {
        if (UIScrollPicture) {
            //緩存App啟動信息
            api.setPrefs({
                key: 'isFirst',
                value: '1'
            });
            //關(guān)閉引導(dǎo)頁模塊
            UIScrollPicture.close();
            //關(guān)閉方法2使用按鈕模塊
            if (UIButton) {
                UIButton.close({
                    id: vButtonId
                });
            }
        }
        //啟動主頁面
        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最后一頁中立即進(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: '立即開啟',
                    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)頁,進(jìn)入主頁面
                    fnStartMainPage();
                }
            });
        } else {
            //模塊已初始化過,直接顯示
            UIButton.show({
                id: vButtonId
            });
        }
    }

    //隱藏進(jìn)入按鈕
    function fnHideStartBtn() {
        if (UIButton) {
            UIButton.hide({
                id: vButtonId
            });
        }
    }

4.清除引導(dǎo)頁狀態(tài)緩存

//清除記錄引導(dǎo)頁狀態(tài)的本地緩存數(shù)據(jù)
    function fnClearCache(){
        api.removePrefs({
            key: 'isFirst'
        });
        api.toast({
            msg: '引導(dǎo)頁緩存數(shù)據(jù)清除成功!',
            duration: 2000,
            location: 'middle'
        });
    }


關(guān)鍵詞:
返回列表