这种动画异常只会影响iOS --安卓会按预期执行动画事件。动画只是用动画的margin-top或top值隐藏和显示<Animated.View/>,但是经过大约4个动画之后,<Animated.View/>中的元素完全消失,我只剩下<Animated.View/>的高度和宽度。
为了正确理解这一点,这里有一些屏幕截图:




然后我就和nO气球玩捉迷藏了。:(
这是代码,这是非常简单的Animated.timing调用,没有什么花哨的东西。
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}],但在文本不透明后留下了一个空格。我想让它从屏幕上消失,但它拒绝回来。为什么?!?
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发布于 2018-06-29 02:05:59
因此,问题是因为我在<Animated.View>中将元素定位为absolute;然而,问题并不是因为我的元素定位为absolute (尽管移除absolute定位确实解决了这个问题,但在没有绝对值灵活性的情况下设置样式很麻烦),而是因为这些元素直接是<Animated.View>的子元素,而不是普通的<View>。
因此,这不适用于绝对值:
<Animated.View>
<View style={{ position: 'absolute' }}/>
</Animated.View>但这将会:
<Animated.View>
<View>
<View style={{ position: 'absolute' }}/>
</View>
</Animated.View>希望这对某些人有帮助!我正要放弃为iOS XD制作标题动画的希望。
https://stackoverflow.com/questions/51055637
复制相似问题