javascript - React-native - 动画 MapViewMarker
问题描述
我一直试图让动画在地图视图标记上进行,但到目前为止还没有运气。我尝试了很多不同的版本,但都失败了。我正在从 react-native 导入 Animated ,这是我的标记:
<MapView.Marker.Animated
key={marker.name}
coordinate={{
latitude: marker.lat,
longitude: marker.lng,
animation: Animated.DROP,
}}
解决方案
Animated API 并不是这样工作的。首先,您需要实例化一些 Animated 值。像这样的东西:
constructor(props) {
super(props)
this.state = {
animatedTop: new Animated.Value(0)
}
}
我还将包装您想要动画的标记组件,如下所示:
render() {
return (
<Animated.View style={{top: this.state.animatedTop}}>
<MapView.Marker {...} />
</Animated.View>
)
}
您需要手动启动动画并告诉 API 您要做什么。超级简单的例子:
componentDidMount() {
Animated.timing(this.state.animatedTop, {
toValue: 200, // position where you want the component to end up
duration: 400 // time the animation will take to complete, in ms
}).start()
}
我强烈建议花一些时间使用Animated API。它有许多不同的效果和缓动可用。
推荐阅读
- html - 使用带有表格滚动且无页面滚动的 CSS Grid 的带有粘性标题的表格
- blockchain - 以太坊/BSC 区块链交易数据
- pandas - 一个双胞胎人物上的两个 Seaborn 情节变得扭曲
- hyperledger-fabric - 超级账本结构链码事件
- excel - 如何在 VBA 中为我的 cmd 计划任务创建参数?
- python - Pandas - 从字典创建数据框时重复行
- kotlin - Kotlin - Firestore - 带有两个集合的内部查询并将其传递给 mutableList
- microprocessors - ATmega328p 和 LC-3 指令
- docker - Airflow 2.0,关系“连接”不存在
- r - 将多个ggpredict图合并为一个