gpt4 book ai didi

不遵守GWT Animation最终值

转载 作者:行者123 更新时间:2023-12-04 18:16:28 25 4
gpt4 key购买 nike

我有一个FlowPanel,我想像iphone导航一样来回进行动画处理。 (有关我的原始问题,请参阅this帖子,有关如何执行此操作)

因此,我将其与下面显示的代码“配合使用”。我说用引号引起来是因为我发现滚动条的最终位置不精确,并且在滚动时总是会变化。

GWT.log总是说出我正在寻找的实际值,因此例如,下面的对scrollTo的调用,我的GWT.log说:

ScrollStart: 0 scrollStop: -246



但是,当我实际分析fireBug中的元素时,它的CSS左位置永远不会精确地为-246px。有时它最多偏离10像素,所以我的面板在完成之前就停止了滚动。

最糟糕的是,该导航会来回动画,因此随后的单击确实会使其失去效果,因此我需要像素完美的定位,否则整个外观都会消失。

除了已经完成的工作外,我什至不知道从哪里开始调试。任何提示,不胜感激。

编辑:其他日志记录信息:
在onUpdate内登录将显示以下内容:
Updating: progress: 0.09319577524960648 position: -22.926160711403195
Updating: progress: 0.1328387452821571 position: -32.67833133941065
Updating: progress: 0.609071620698271 position: -149.83161869177468
Updating: progress: 0.7269952498697734 position: -178.84083146796425
Updating: progress: 0.9852532367342712 position: -242.37229623663072
AnimationComplete: final scrollStart/scrollStop: 0/-246

为什么以0.98%结束呢???

调用动画的代码
scroller = new Scroller();
scroller.scrollTo(-246,400);

动画代码
public class Scroller extends Animation {

private FlowPanel scroller;
private final Element e;

public Scroller(){
scroller = new FlowPanel();
e = scroller.getElement();
}

public void scrollTo(int position, int milliseconds) {

scrollStart = e.getOffsetLeft();
scrollStop = position;

GWT.log("ScrollStart: " + scrollStart + " scrollStop: " + scrollStop);
run(milliseconds);
}

@Override
protected void onUpdate(double progress) {
double position = scrollStart + (progress * (scrollStop - scrollStart));
e.getStyle().setLeft(position, Style.Unit.PX);
}
}

最佳答案

动画完成时会调用onComplete(并且onStart在开始播放之前会被调用),因此,如果要在动画100%完成后执行操作,请覆盖它:

public class Scroller extends Animation {
...

@Override
protected void onComplete() {
e.getStyle().setLeft(scrollStop, Style.Unit.PX);
}
}

编辑如布拉德所说,文档并不是很清楚动画完成后会调用onComplete。 Javadoc说 Animation.onUpdate是:

Called when the animation should be updated. The value of progress is between 0.0 and 1.0 inclusively (unless you override the interpolate(double) method to provide a wider range of values). You can override onStart() and onComplete() to perform setup and tear down procedures.



code that calls these methods是唯一可以清楚表明onUpdate仅在动画开始但尚未完成时才调用的方法,即,当进度值> 0但<1时。

关于不遵守GWT Animation最终值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2669065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com