我有一个ScrollView
,顶部有一个背景 colored颜色 ,底部有另一个不同的 colored颜色 .
当用户滚动浏览内容时,视图会反弹(弹性过度延伸),我如何根据滚动方向使背景与顶部或底部一致?
我有一个ScrollView
,顶部有一个背景 colored颜色 ,底部有另一个不同的 colored颜色 .
当用户滚动浏览内容时,视图会反弹(弹性过度延伸),我如何根据滚动方向使背景与顶部或底部一致?
在iOS上,您可以在ScrollView
的顶部渲染间隔View
,并使用contentInset
将其渲染为"屏幕外",contentOffset
将初始滚动位置设置为偏移插图:
render() {
const isIos = Platform.OS === 'ios'
const SPACER_SIZE = 1000; //arbitrary size
const TOP_COLOR = 'white';
const BOTTOM_COLOR = 'papayawhip';
return (
<ScrollView
style={{backgroundColor: isIos ? BOTTOM_COLOR : TOP_COLOR }}
contentContainerStyle={{backgroundColor: TOP_COLOR}}
contentInset={{top: -SPACER_SIZE}}
contentOffset={{y: SPACER_SIZE}}>
{isIos && <View style={{height: SPACER_SIZE}} />}
//...your content here
</ScrollView>
);
}
因为contentInset
和contentOffset
是iOS only,所以这个例子的条件是在Android上优雅地降级.