首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >React原生TabBarIOS过渡动画?

React原生TabBarIOS过渡动画?
EN

Stack Overflow用户
提问于 2015-09-26 05:32:37
回答 1查看 537关注 0票数 2

是否可以对由TabBarIOS呈现和显示的视图进行转换?Navigator组件提供了它们。我必须实现一个导航器,并通过TabBarIOS控制它,这看起来有点冗长

EN

回答 1

Stack Overflow用户

发布于 2016-03-09 08:31:54

React Native v0.21

代码语言:javascript
复制
class Tabs extends Component {

  constructor(props) {
    super(props)

    this.state = {
      tab: 1
    }
  }

  render() {

    this.anim = new Animated.Value(0)

    return (
      <View style={{ flex: 1 }}>
        <TabBarIOS>
          <TabBarIOS.Item
            title="Tab 1"
            selected={this.state.tab === 1}
            onPress={() => {
              this.setState({
                tab: 1
              })

              Animated.spring(this.anim, {
                toValue: 0,
                velocity: 3,
                tension: -10, 
                friction: 1
              }).start()
            }}>
            <Animated.View style={[{
              flex: 1,
              backgroundColor: 'red',
              justifyContent: 'center',
              alignItems: 'center',
              transform: [   
                {
                  scale: this.anim.interpolate({
                    inputRange: [0, 1],
                    outputRange: [1, 4],
                  })
                },
                {
                  translateX: this.anim.interpolate({
                    inputRange: [0, 1],
                    outputRange: [0, 500],
                  })
                },
                {
                  rotate: this.anim.interpolate({
                    inputRange: [0, 1],
                    outputRange: [
                      '0deg', '360deg'
                    ],
                  })
                },
              ]
            }]}>
              <Text>Tab 1</Text>
            </Animated.View>
          </TabBarIOS.Item>
          <TabBarIOS.Item
            title="Tab 2"
            selected={this.state.tab === 2}
            onPress={() => {
              this.setState({
                tab: 2
              })
            }}>
            <Text>Tab 2</Text>
          </TabBarIOS.Item>
        </TabBarIOS>
      </View>
    )
  }
}

基于来自https://github.com/facebook/react-native/blob/0.21-stable/Examples/UIExplorer/AnimatedExample.js#L105-L141Animated示例

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32790962

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档