2016-04-06 29 views
2

我創建一個自定義層,根據這個材料: http://docs.gluonhq.com/charm/2.1.1/#_creating_a_layer,並將其添加到我的應用程序:是否可以在閃光層上使用轉場?

MobileApplication.getInstance().addLayerFactory(LAYER_NAME,() -> customLayer); 

現在我想轉場添加到這一層。您可以使用View上的轉換:view.setShowTransitionFactory(BounceInDownTransition:new)

Layer不提供類似的方法。所以,我想這種方法適用的轉換:當我打電話showLayer()首次過渡似乎是不完整的

private void showLayer() { 
    MobileApplication.getInstance().showLayer(LAYER_NAME); 
    new BounceInDownTransition(customLayer).play(); 
} 

。第一部分,圖層應該從視圖中轉換出來,但是缺失。每進一步調用showLayer()都會顯示完整的轉換。

層是否意味着與轉換結合使用? 如果可能,推薦的方法是什麼?

+0

的[發佈](http://gluonhq.com/gluon-mobile-2-2-0-released/)新的魅力2.2.0版本已經包含層轉換 –

回答

2

您可以使用Gluon Charm中的內置過渡,因爲您只需要將節點傳遞給它們,然後調用播放來啓動動畫。

如果使用膠子的層,沒有視圖的內置機制,但是您可以輕鬆地將其添加到您的課堂。

這將爲隱藏的顯示和反彈效果創建彈跳效果。

public class MyLayer extends Layer { 

    private final Node root; 
    private final double size = 150; 

    public MyLayer() { 
     final BounceInDownTransition transitionIn = new BounceInDownTransition(this, true); 
     final BounceOutDownTransition transitionOut = new BounceOutDownTransition(this, true); 
     transitionOut.setOnFinished(e -> hide()); 

     Button button = new Button("", MaterialDesignIcon.CLOSE.graphic()); 
     button.setOnAction(e -> transitionOut.playFromStart()); 
     root = new StackPane(button); 
     root.setStyle("-fx-background-color: white;"); 
     getChildren().add(root); 

     getGlassPane().getLayers().add(this); 

     showingProperty().addListener((obs, ov, nv) -> { 
      if (nv) { 
       layoutChildren(); 
       setOpacity(0); 
       transitionIn.playFromStart(); 
      } 
     }); 
    } 

    @Override 
    public void show() { 
     getGlassPane().setBackgroundFade(GlassPane.DEFAULT_BACKGROUND_FADE_LEVEL); 
     super.show(); 
    } 

    @Override 
    public void hide() { 
     getGlassPane().setBackgroundFade(0.0); 
     super.hide(); 
    } 

    @Override 
    public void layoutChildren() { 
     root.setVisible(isShowing()); 
     if (!isShowing()) { 
      return; 
     } 
     root.resize(size, size); 
     resizeRelocate((getGlassPane().getWidth() - size)/2, (getGlassPane().getHeight()- size)/2, size, size); 
    } 
} 

而現在,添加層:

@Override 
public void init() { 
    addViewFactory(BASIC_VIEW,() -> new BasicView(BASIC_VIEW)); 

    addLayerFactory("My Layer",() -> new MyLayer()); 
} 
+0

仍然獲得相同的效果。轉換的第一幀(s)缺失... – jns

+0

是的,我也注意到了它。我已經修改了我的答案:在開始動畫之前調用'layoutChildren()'。無論如何,我會爲此創建一個內部問題。 –

+0

這個問題應該用新的Charm 2.2.0版本的[release](http://gluonhq.com/gluon-mobile-2-2-released/)修復。你可以檢查一下嗎? –

相關問題