【问题标题】:Is it possible to use transitions on glisten layers?是否可以在闪亮层上使用过渡?
【发布时间】:2016-04-06 22:00:17
【问题描述】:

我根据这个材料创建了一个自定义层: http://docs.gluonhq.com/charm/2.1.1/#_creating_a_layer,并将其添加到我的应用程序中:

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

现在我想为这个图层添加一个过渡。您可以在View 上使用转换,例如:view.setShowTransitionFactory(BounceInDownTransition:new)

Layer 没有提供这样的方法。所以我尝试了这种方法来应用过渡:

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

当我第一次致电showLayer() 时,转换似乎不完整。第一部分,图层应该被转移到视野之外的地方,丢失了。每次进一步调用showLayer() 都会显示完整的转换。

层是否意味着与过渡结合使用? 如果可能,推荐的方式是什么?

【问题讨论】:

  • Charm 2.2.0 新版本的release 已经包含图层过渡

标签: gluon gluon-mobile


【解决方案1】:

您可以使用 Gluon Charm 中的内置转换,因为您只需将一个节点传递给它们,然后调用 play 来启动动画。

在 Gluon 层的情况下,没有视图的内置机制,但您可以轻松地将其添加到您的类中。

这将创建用于显示的反弹效果和用于隐藏的反弹效果。

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());
}

【讨论】:

  • 是的,我也注意到了。我已经通过修复编辑了我的答案:在开始动画之前调用layoutChildren()。无论如何,我会为此创建一个内部问题。
  • 这个问题应该用新 Charm 2.2.0 版本的release 修复。可以查一下吗?
猜你喜欢
  • 2020-12-05
  • 2014-08-30
  • 2017-01-12
  • 1970-01-01
  • 2022-01-03
  • 2017-11-22
  • 1970-01-01
  • 2015-08-15
  • 2014-07-19
相关资源
最近更新 更多