onPress中的React-native Animatable旋转视图

问题描述 投票:1回答:1

我正在尝试使用以下方式旋转图像:

this.myView.transitionTo({ rotate: '180deg' }, 200);

我收到错误:

不变违规:使用“rotate”键进行转换必须是字符串:{“rotate”:null}

使用react-native-animatable库。不确定用于转换道具的正确语法是什么。

谢谢。

react-native react-native-animatable
1个回答
0
投票

尝试这个适合我的。

import * as Animatable from "react-native-animatable";

export default class App extends Component {
  constructor() {
    super();
    this.state = {
      back: false
    };
  }
  render() {
    return (
      <TouchableOpacity
        onPress={() => this.setState({ back: !this.state.back })}
      >
        <Animatable.Image
          source={require("./assets/images/nike.png")}
          style={{ width: 100, height: 100 }}
          animation={{
            from: {
              rotate: this.state.back ? "180deg" : "0deg"
            },
            to: {
              rotate: this.state.back ? "180deg" : "0deg"
            }
          }}
        />
      </TouchableOpacity>
    );
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.