2017-02-21 59 views
1

我有一個窗口和一個視圖,這個視圖覆蓋了屏幕的76%。如何製作鈦金屬的幻燈片動畫

var win = Ti.UI.createWindow({ 
    backgroundColor: 'white', 
    navBarHidden: true, 
}); 

var view = Ti.UI.createView({ 
    backgroundColor:backgroundColor , 
    width:'76%',right:0,left:'24%', 
    height:'100%' 
}); 

win.addEventListener('click',function(e){ 
    win.add(view); 
}); 

我想要做的是從右側滑動屏幕滑動視圖。 我該怎麼做? 我想我應該使用動畫方法雖然,,,, 有沒有人有樣品來源或東西?

回答

1

要創建動畫,您確實需要使用animate方法。 下面是一個例子:

var view = Ti.UI.createView({ 
    backgroundColor:'yellow', 
    width:'76%', 
    right:-Ti.Platform.displayCaps.getPlatformWidth(), 
    onScreen:false 
}); 
win.tiview.add(view); 

win.tiview.addEventListener('click',function(e){ 
    var viewShowAnimation = Ti.UI.createAnimation({ 
     duration:250, 
     right:0 
    }); 
    var viewHideAnimation = Ti.UI.createAnimation({ 
     duration:250, 
     right:-Ti.Platform.displayCaps.getPlatformWidth() 
    }); 
    if(view.onScreen){ 
     view.animate(viewShowAnimation); 
    }else{ 
     view.animate(viewHideAnimation); 
    } 
    view.onScreen = !view.onScreen; 
}); 
+1

非常感謝你!!!!它幫助到我。也許在示例代碼中,if(view.onScreen){'應該是if(!view.onScreen){'。 – whitebear