[英]React-native - Animation MapViewMarker
I have been trying to get the animation going on a mapview marker but so far no luck. 我一直在尝试使动画在mapview标记上进行,但到目前为止还没有运气。 I have tried a bunch of different versions but they all fall flat.
我尝试了很多不同的版本,但是它们都变平了。 I am importing Animated from react-native and this is my marker:
我正在从react-native导入Animated,这是我的标记:
<MapView.Marker.Animated
key={marker.name}
coordinate={{
latitude: marker.lat,
longitude: marker.lng,
animation: Animated.DROP,
}}
The Animated API doesn't really work that way. Animated API并不是真的那样。 First, you need to instantiate some Animated values.
首先,您需要实例化一些Animated值。 Something like this:
像这样:
constructor(props) {
super(props)
this.state = {
animatedTop: new Animated.Value(0)
}
}
I would also wrap the marker components you'd like to animate, something like this: 我还将包装要设置动画的标记组件,如下所示:
render() {
return (
<Animated.View style={{top: this.state.animatedTop}}>
<MapView.Marker {...} />
</Animated.View>
)
}
You need to manually kick off the animation and tell the API what you're after. 您需要手动启动动画并告诉API您要做什么。 Super simple example:
超级简单的例子:
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()
}
I highly recommend spending some time with the Animated API . 我强烈建议您花一些时间使用Animated API 。 It has a bunch of different effects and easings available.
它具有许多不同的效果和放松效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.