问题
我有一个显示文本的应用程序。它需要在 X 时间内滚动到页面底部。现在它正在工作,但并不顺利。它一点一点地进行,因为我调用该函数每 1000 毫秒滚动一次,将滚动位置设置为 X。
目标
使用 ScrollView 和 Animate 进行平滑滚动。滚动需要持续 1000 毫秒并且需要是线性的,没有缓动。(因为我将每 1000 毫秒调用一次函数以继续滚动)。还是有更好的选择?
我试过什么
我已经尝试了一切,包括查找教程和在这里挖掘。有很多关于滚动的东西,但没有什么能帮助我。也许它真的很容易,这就是为什么它什么都没有,我希望它是。
还尝试了“LayoutAnimation.configureNext(LayoutAnimation.Presets.linear);” 选项。使用它时,我的屏幕上有很多动画,而不是滚动。
这是我当前的滚动设置,如我的问题中所述:
*设置间隔每1000ms滚动一次。
_pixels = amount of pixels to scroll. _steps = amount of steps it will take to get to the bottom using _pixels distance. _distance = total height of the page in pixels. _interval = 1000ms.
setInterval((data) => this.scrollSong(_pixels, _steps, _distance), _interval);
在功能scrollSong
中滚动。(_scrollTo = 要滚动到的位置):
this._scrollView.scrollTo({y: _scrollTo, animated: true});
滚动视图。在开始和结束滚动时,scrollSong
间隔会暂停。
<ScrollView ref={(scrollView) => { this._scrollView = scrollView; }} onScrollBeginDrag={this.handleBeginScroll} onScrollEndDrag={this.handleEndScroll}>
我希望你能帮助我。如果您需要任何信息,请告诉我。