我正在尝试构建我的第一个动画,我只想让球体旋转(比如头部向左或向右转)。
我查看了动画 API,但出现以下错误:
使用“rotateY”键进行转换必须是字符串或数字:{“rotateY”:0}
就像我的动画对象无法被 react-vr 解析一样。
这是我尝试过的:
import React from 'react';
import {
Animated,
AppRegistry,
asset,
Pano,
Sphere,
View,
} from 'react-vr';
const sphereProps = {
radius: 0.5,
widthSegments: 20,
heightSegments: 12
};
export default class Test extends React.Component {
constructor() {
super();
this.state = {
viewPoint: new Animated.Value(0)
};
}
turnLeft = () => {
Animated.timing(
this.state.viewPoint,
{
toValue: -20,
duration: 3000
}
).start();
}
turnRight = () => {
Animated.timing(
this.state.viewPoint,
{
toValue: 20,
duration: 3000
}
).start();
}
render() {
return (
<Animated.View>
<Pano source={asset('background.jpg')}/>
<Sphere
{ ...sphereProps }
style={{
color: 'blue',
transform: [
{ translate: [0, 0, -4] },
{ rotateY: this.state.viewPoint }
],
}}
/>
</Animated.View>
);
}
componentDidMount() {
this.turnLeft();
}
};
AppRegistry.registerComponent('Test', () => Test);
即使我不调用该#turnLeft
方法,也会在渲染组件时发生错误。
你知道我们应该如何实现这种动画旋转吗?