我开始在我的react-native项目中为图像制作动画,但不知何故我无法为blurRadius
属性设置动画效果。 Translate
和Scale
工作得很好。 这里是我用来interpolat
Ë值模糊,规模和翻译代码:Animate blurRadius属性与反应原生
// 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 }] }
]}
/>
);
我绑定在ScrollView
滚动的this.state.scrollY
值。
动画blurRadius类型的作品在0.51,但我得到了一些严重的性能问题与Android特别是。 – 30secondstosam