【问题标题】:Difference between Timeline's stop() and jumpTo("end")Timeline 的 stop() 和 jumpTo("end") 的区别
【发布时间】:2016-09-20 11:57:07
【问题描述】:

有人能解释一下timeline.stop()timeline.jumpTo("end") 之间的区别吗?

【问题讨论】:

    标签: animation javafx javafx-8


    【解决方案1】:

    Timeline.stop() 停止动画并确保Timeline.play() 从动画的开头开始; “当前运行”不再更新。

    timeline.jumpTo("end") 转到位于动画末尾的标记"end"。这与timeline.jumpTo(timeline.getTotalDuration()) 的效果相同。任何到达那个时间的动画效果都会被执行。

    您可以在以下示例中观察到不同的行为:

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button("Play / (Stop/Jump)");
    
        Timeline timeline = new Timeline(
                new KeyFrame(Duration.ZERO, new KeyValue(btn.translateXProperty(), 0d)),
                new KeyFrame(Duration.seconds(10), new KeyValue(btn.translateXProperty(), 200d))
        );
    
        btn.setOnAction((ActionEvent event) -> {
            if (timeline.getStatus() == Animation.Status.RUNNING) {
    //            timeline.jumpTo("end");
                timeline.stop();
            } else {
                timeline.play();
            }
        });
    
        StackPane root = new StackPane();
        root.getChildren().add(btn);
    
        Scene scene = new Scene(root, 400, 400);
    
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    

    timeline.jumpTo("end")Button 移动到动画的终点,timeline.stop()Button 停止在当前位置。

    【讨论】:

      猜你喜欢
      • 2019-07-06
      • 2013-09-06
      • 1970-01-01
      • 2015-01-11
      • 2013-11-02
      • 2015-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多