我開始在我的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