首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动画视图的动画顶部逐渐隐藏了内部的元素

问动画视图的动画顶部逐渐隐藏了内部的元素
EN

Stack Overflow用户
提问于 2018-06-27 14:08:55
回答 1查看 2.6K关注 0票数 0

这种动画异常只会影响iOS --安卓会按预期执行动画事件。动画只是用动画的margin-top或top值隐藏和显示<Animated.View/>,但是经过大约4个动画之后,<Animated.View/>中的元素完全消失,我只剩下<Animated.View/>的高度和宽度。

为了正确理解这一点,这里有一些屏幕截图:

​

​

然后我就和nO气球玩捉迷藏了。:(

这是代码,这是非常简单的Animated.timing调用,没有什么花哨的东西。

代码语言:javascript
复制
componentWillReceiveProps = (nextProps) => { 
    if (this.props.animated && this.props.animate !== nextProps.animate) {
      if (nextProps.animate) {
        Animated.parallel([
          Animated.timing(
            this.animatedTop, {
              toValue: 0, // Show the header
              duration: 1000,
            }
          ),
          Animated.timing(
            this.opacity, {
              toValue: 1,
              duration: 1300,
            }
          )
        ]).start()
      } else {
        Animated.parallel([
          Animated.timing(
            this.animatedTop, {
              toValue: this.hiddenTop, // Hide the header ... no, no, don't go! X|
              duration: 1000,
            }
          ),
          Animated.timing(
            this.opacity, {
              toValue: 0,
              duration: 800,
            }
          )
        ]).start()
      }
    }
  }

正如你可以想象的,其他一切都很正常,就像蜜蜂一样。动画在安卓上运行得很好,但这在iOS...why上发生了吗?我尝试过transform: [{translateY: this.animatedTop}],但在文本不透明后留下了一个空格。我想让它从屏幕上消失,但它拒绝回来。为什么?!?

代码语言:javascript
复制
Environment:
  OS: macOS Sierra 10.12.6
  Node: 6.11.0
  Yarn: 1.7.0
  npm: 5.3.0
  Watchman: 4.9.0
  Xcode: Xcode 9.2 Build version 9C40b
  Android Studio: 3.0 AI-171.4443003
Packages:
  react: 16.3.1
  react-native: ~0.55.2
EN

回答 1

Stack Overflow用户

发布于 2018-06-29 02:05:59

因此,问题是因为我在<Animated.View>中将元素定位为absolute;然而,问题并不是因为我的元素定位为absolute (尽管移除absolute定位确实解决了这个问题,但在没有绝对值灵活性的情况下设置样式很麻烦),而是因为这些元素直接是<Animated.View>的子元素,而不是普通的<View>。

因此,这不适用于绝对值:

代码语言:javascript
复制
<Animated.View>
  <View style={{ position: 'absolute' }}/>
</Animated.View>

但这将会:

代码语言:javascript
复制
<Animated.View>
  <View>
    <View style={{ position: 'absolute' }}/>
  </View>
</Animated.View>

希望这对某些人有帮助!我正要放弃为iOS XD制作标题动画的希望。

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

https://stackoverflow.com/questions/51055637

复制
相关文章

相似问题

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