android - 使用 React Native 在 View 上显示 3D 动画

标签 android ios css reactjs react-native

我想在我的 React Native 应用程序中实现翻转效果,类似于此处所述:

https://www.codementor.io/reactjs/tutorial/building-a-flipper-using-react-js-and-less-css

我的问题是。我可以在“动画”之类的库的帮助下以某种方式实现它https://facebook.github.io/react-native/docs/animations.html或者我必须使用“普通”CSS 样式。

React Native 中此类动画的“良好实践”是什么?

class CardBack extends Component {
  render() {
    return (
      <TouchableOpacity onPress={this.flip}>
        <View style={styles.scrumCardBorder}>
          <View style={styles.cardBack}>
          </View>
        </View>
      </TouchableOpacity>
    );
  }

  flip() {
    this.setState({flipped: !this.state.flipped})
  }
}

class CardFront extends Component {
  render() {
    return (
      <TouchableOpacity>
        <View style={styles.scrumCardBorder}>
          <View style={styles.cardFront}>
            <Text style={styles.cardValue}>5</Text>
          </View>
        </View>
      </TouchableOpacity>
    );
  }
}

最佳答案

我们可以使用transformInterpolate制作 3D 旋转动画。

class RotateAnimation extends React.Component {
  _rotateValue = new Animated.Value(0);
  startAnimated = () => {
    Animated.timing(this._rotateValue, {
      toValue: 360,
      duration: 800, 
      useNativeDriver: true 
    }).start()
  }

  getTransform = () => {
    const rotate = this._rotateValue.interpolate({
      inputRange: [0, 180, 360], 
      outputRange: ['0deg', '180deg', '360deg'], 
      extrapolate: 'clamp',
    }) 
    if (this.props.horizontal) {
      return {
        transform: {
          perspective: WINDOW_WIDTH, 
          rotateX: rotate
        }
      }
    }

    return {
      transform: {
        perspective: WINDOW_WIDTH, 
        rotateY: rotate
      }
    }
  }

  render() {
    return  (<Animated.View style={[style, ]} />
      {this.props.children}
    </Animated.View>)
  }
}

如果你想在某个点周围使用变换。可以试试this

关于android - 使用 React Native 在 View 上显示 3D 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33938137/

相关文章:

ios - Backendless + Realm - 存储数组

css - 如何在网页的右侧和左侧对齐页脚文本?

java - 如何转到上一个 Activity 搜索 View 后退按钮?

ios - 设置 HTTP 方法 : @"POST" not working

ios - 如何在我的选项卡栏应用程序 (iPad) 中创建 UISplitViewController?

jQuery CSS 高度

css - 调整div中多行跨度的行高

安卓FTP下载

Android picasso,报错原因

android - FFmpeg 无法为 android 构建