【发布时间】:2017-06-29 12:52:17
【问题描述】:
我开始在我的 react-native 项目中为图像制作动画,但不知何故我无法为 blurRadius 属性制作动画。 Translate 和 Scale 工作正常。
这是我用于 interpolate 模糊、缩放和平移值的代码:
// Compute image position
const imageTranslate = this.state.scrollY.interpolate({
inputRange: [-IMAGE_MAX_HEIGHT, 0, IMAGE_MAX_HEIGHT],
outputRange: [IMAGE_MAX_HEIGHT / 2, 0, -IMAGE_MAX_HEIGHT / 3],
extrapolate: 'clamp',
});
// Compute image blur
const imageBlur = this.state.scrollY.interpolate({
inputRange: [0, IMAGE_MAX_HEIGHT],
outputRange: [0, 100],
extrapolate: 'clamp',
});
// Compute image scale
const imageScale = this.state.scrollY.interpolate({
inputRange: [-IMAGE_MAX_HEIGHT, 0, IMAGE_MAX_HEIGHT],
outputRange: [2, 1, 1],
extrapolate: 'clamp',
});
这是我的图片:
return (
<Animated.Image
blurRadius={imageBlur}
source={this.props.imgSrc}
style={[
animatedImageStyles.backgroundImage,
{ transform: [{ translateY: imageTranslate }, { scale: imageScale }] }
]}
/>
);
我将this.state.scrollY 值绑定到ScrollView 滚动条上。
【问题讨论】:
-
动画 blurRadius 类型在 0.51 中有效,但我遇到了一些严重的 Android 性能问题。
标签: animation react-native react-animated