标准的iOS天气应用程序有一个特殊的滚动UI行为:

UI中有不同的部分:上部(大20)、中间(水平)栏、下半部(平日和页脚)。
当你向上滚动时,

我如何在realized中实现类似的东西?--我不需要所有的细节,只需要知道如何实现上半部分,即一个组件在滚动时崩溃,直到它固定在顶部,并且有一个最小的高度。
当然,我更喜欢纯RN解决方案,它既适用于iOS,也适用于安卓。
发布于 2019-05-31 12:00:32
找到了一个例子这里。
只有真正滚动的部分在ScrollView中,而折叠部分则不是。然后连接到ScrollView.onScroll事件,并通过Animated.event和Animated.interpolate将contentOffset属性连接到标头的高度:
const HEADER_EXPANDED_HEIGHT = 300
const HEADER_COLLAPSED_HEIGHT = 60
export default class App extends Component {
constructor() {
super()
this.state = {
scrollY: new Animated.Value(0)
}
}
render() {
const headerHeight = this.state.scrollY.interpolate({
inputRange: [0, HEADER_EXPANDED_HEIGHT-HEADER_COLLAPSED_HEIGHT],
outputRange: [HEADER_EXPANDED_HEIGHT, HEADER_COLLAPSED_HEIGHT],
extrapolate: 'clamp'
})
return(
<View style={styles.container}>
<Animated.View style={{height: headerHeight}}/>
<ScrollView
contentContainerStyle={styles.scrollContainer}
onScroll={Animated.event(
[{ nativeEvent: {
contentOffset: {
y: this.state.scrollY
}
}
}])}
scrollEventThrottle={16}>
...
</ScrollView>
</View>
)
}
}https://stackoverflow.com/questions/56393903
复制相似问题