試圖用預期和過沖來插入 javafx 時間軸,我發現了
但我得到的是一個 RuntimeException
Caused by: java.lang.IllegalArgumentException: Control point coordinates must all be in range [0,1]
at com.sun.scenario.animation.SplineInterpolator.<init>(SplineInterpolator.java:98)
at javafx.animation.Interpolator.SPLINE(Interpolator.java:199)
現在我的問題是為什么在 SplineInterpolator 中使用小于 0 或大于 1 的 Y 值是非法的,以及在 javafx 中制作預期/過沖插值器的最方便的方法是什么?
添加 MRE
我正在嘗試使用時間軸在 StackPane 中的兩個節點之間進行轉換,但我需要用預期/過沖來插入它
public class App extends Application {
@Override
public void start(Stage ps) throws Exception {
//Setting up the scene
VBox root = new VBox();
root.setBackground(new Background(new BackgroundFill(Color.GRAY, null, null)));
StackPane cards = new StackPane();
cards.setMinSize(600, 600);
StackPane card1 = new StackPane(new Label("Card 1"));
card1.setMaxSize(400, 200);
card1.setBackground(new Background(new BackgroundFill(Color.WHITE, new CornerRadii(10), null)));
StackPane card2 = new StackPane(new Label("Card 2"));
card2.setMaxSize(200, 400);
card2.setBackground(card1.getBackground());
cards.getChildren().addAll(card1, card2);
HBox buttons = new HBox(10);
buttons.setPadding(new Insets(10));
buttons.setAlignment(Pos.CENTER);
Button show1 = new Button("Card 1");
Button show2 = new Button("Card 2");
buttons.getChildren().addAll(show1, show2);
root.getChildren().addAll(cards, buttons);
//adding behaviour
double duration = .3;
Interpolator interpolator = Interpolator.EASE_BOTH;
Timeline showCard1 = new Timeline(new KeyFrame(Duration.seconds(duration),
new KeyValue(card1.opacityProperty(), 1, interpolator),
new KeyValue(card1.scaleXProperty(), 1, interpolator),
new KeyValue(card1.scaleYProperty(), 1, interpolator),
new KeyValue(card1.translateYProperty(), 0, interpolator),
new KeyValue(card2.opacityProperty(), 0, interpolator),
new KeyValue(card2.scaleXProperty(), .5, interpolator),
new KeyValue(card2.scaleYProperty(), .5, interpolator),
new KeyValue(card2.translateYProperty(), -100, interpolator)
));
Timeline showCard2 = new Timeline(new KeyFrame(Duration.seconds(duration),
new KeyValue(card2.opacityProperty(), 1, interpolator),
new KeyValue(card2.scaleXProperty(), 1, interpolator),
new KeyValue(card2.scaleYProperty(), 1, interpolator),
new KeyValue(card2.translateYProperty(), 0, interpolator),
new KeyValue(card1.opacityProperty(), 0, interpolator),
new KeyValue(card1.scaleXProperty(), .5, interpolator),
new KeyValue(card1.scaleYProperty(), .5, interpolator),
new KeyValue(card1.translateYProperty(), -100, interpolator)
));
show1.setOnAction(e-> {
showCard2.stop();
showCard1.playFromStart();
});
show2.setOnAction(e-> {
showCard1.stop();
showCard2.playFromStart();
});
show1.fire();
Scene scene = new Scene(root);
ps.setScene(scene);
ps.show();
}
}
(該示例使用 easy_both 插值,因為嘗試使用具有超出范圍的值的樣條曲線會產生上述錯誤)
uj5u.com熱心網友回復:
為什么在 SplineInterpolator 中使用小于 0 或大于 1 的 Y 值是非法的,
我不知道。
在 javafx 中制作預期/過沖插值器的最方便的方法是什么?
創建您自己的實作。
擴展插值器,不要在你的實作中使用范圍檢查,對它進行單元測驗以確保它執行你想要的功能。
您可能希望從示例實作開始。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/335519.html
下一篇:使用標題和串列改進css文本影片
