首页 > 解决方案 > 动画图像没有透明背景

问题描述

在我的 react-native 应用程序中,我想将旋转徽标呈现为屏幕的正确标题。

<Stack.Screen
      name="About"
      component={About}
      options={{headerRight: () => <SpinnerIcon />}}
    />

微调器组件返回一个Animated.Image

<Animated.Image
        source={require('../img/reactLogoTwo.png')}
        style={[{width: 50, height: 50}, {transform: [{rotate}]}]}
      />

我保存在img文件夹中的图像具有透明背景(从此处下载),但动画图像呈现为白色背景。

在此处输入图像描述

注意:添加backgroundColor: 'transparent'不起作用。

标签: reactjsreact-nativereact-animatedreact-native-stylesheet

解决方案


我把这个例子当作零食:https ://snack.expo.io/@zvona/animated-transparent-image

根据它,透明 PNG 和Animated.Image. 你在使用react-native-animated库吗?

其次,设置风格backgroundColor: 'transparent'可能会有所帮助,但我看不出是什么导致了这种特殊行为。


推荐阅读