2017-04-18 40 views
1

我有滾動視圖與pagingEnabled通過圖片,工作正常滾動,但它將會滾動顯示第二圖像的一半,看到gif動​​畫連接使用React Native使scrollView在x軸上移動特定大小?

https://media.giphy.com/media/xUA7b6pv9MNdp0R97O/giphy.gif

代碼:

<ScrollView 
    style={{flex:1}} 
    horizontal 
    ref={(scrollView) => { this.scrollView = scrollView }} 
    automaticallyAdjustContentInsets={false} 
    directionalLockEnabled 
    alwaysBounceVertical={false} 
    pagingEnabled 
    scrollsToTop={false}> 


    <Image style={styles.destination} source={require("../images/favdest1.jpg")} /> 
    <Image style={styles.destination} source={require("../images/favdest1.jpg")} /> 
    <Image style={styles.destination} source={require("../images/favdest1.jpg")} /> 


</ScrollView> 

如何使scrollView捕捉到特定寬度或子視圖?

回答

1

React Native ScrollView無法直接捕捉到給定的寬度;

onScrollEndDrag:但是,您可以通過以下道具實現這個功能,獲取滾動

onMomentumScrollEnd後,只要用戶提起手指離開屏幕叫:功能,被稱爲一旦ScrollView在用戶將手指從屏幕上擡起之後由於模擬動量而停止滑動。

您可以使用這些方法來確定用戶是否已停止滾動並在ScrollView上調用scrollTo以使視圖「捕捉」到所需的寬度。

但是,這是非常不平凡的,並且您想要的功能已經存在爲react-native-snap-carousel組件。 :)

相關問題