gpt4 book ai didi

react-native - 在React Native中旋转SVG

转载 作者:行者123 更新时间:2023-12-04 05:08:01 27 4
gpt4 key购买 nike

我有一个在react native中创建的SVG,我只是想尽可能以最有效的方式连续旋转360度。

谢谢。

最佳答案

只需将SVG包装在View组件中,然后使用Animated API。您的代码将如下所示:

class YourComponent extends React.Component {

constructor(props) {
super(props);
this.animation = new Animated.Value(0);
}

render() {

const rotation = this.animation.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg']
});

return (
<Animated.View
style={{transform: [{rotate: rotation}] }}
>
<YourSVG />
</Animated.View>
);


componentDidMount() {

Animated.loop(
Animated.timing(this.animation, {toValue: 1, duration: 2000})
).start();
}
}

关于react-native - 在React Native中旋转SVG,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50891046/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com