【问题标题】:React-native ScrollView scrollTo not working as it shouldReact-native ScrollView scrollTo 无法正常工作
【发布时间】:2021-07-23 07:22:37
【问题描述】:

这是我的功能:

const scrollToDown = () =>
positionRef.current.scrollTo({x: -100, y: -100, animated: true});

当调用这个函数时,我希望我的屏幕向下滚动一点,而是一直滚动到屏幕顶部。

有什么建议吗?

【问题讨论】:

标签: react-native


【解决方案1】:

你可以试试这个

    const scrollRef = useRef();

    const onPressTouch = () => {
        scrollRef.current.scrollTo({
            y: 100,
            animated: true,
        });
    }

    <ScrollView ref={scrollRef}>
     ....
    </ScrollView>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2021-10-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多