React Native Image 不会在设备 (iOS) 方向更改时调整大小? [英] React Native Image doesn't resize on device (iOS) orientation change?

查看:64
本文介绍了React Native Image 不会在设备 (iOS) 方向更改时调整大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 React Native n00b,所以也许我遗漏了一些非常明显的东西.

I'm a React Native n00b, so perhaps I'm missing something brutally obvious.

      <Image
        source={signoutGradient}
        resizeMode="cover"
        style={{ height: 60, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0,0,0,0)' }}
      >
        <Button
          title="SIGN OUT"
          color="#FFFFFF"
          onPress={this.onPressSignOut}
        />
      </Image>

...在我的 iOS 设备上给我这个纵向的(好):

... gives me this in portrait on my iOS device (good):

...但是当我旋转设备时,这是横向模式(不好).怎么来的?如何解决这个问题?我希望实际 PNG 图像文件的大小无关紧要,因为如果需要,它应该被拉伸得更大.这似乎没有发生.

... but this in landscape mode (bad) when I rotate the device. How come? How to fix this? I am expecting that the size of the actual PNG image file doesn't matter, because it should get stretched to be larger if it needs to be. That doesn't seem to be happening.

推荐答案

是的,将 flex: 1 添加到您的图像样式应该可以解决您的问题.只要您只设置默认高度而不是宽度.就我而言,我已经为我的图像设置了宽度和高度,并且在设备横向运行时遇到了同样的问题.一旦我删除了宽度并添加了 flex: 1 我的问题就解决了

Yep adding flex: 1 to your image style should fix your issue. As long as you are setting only a default height and not a width. In my case I had set both width and height for my image and had the same issue when the device went landscape. Once I removed the width and added flex: 1 my issue was resolved

这篇关于React Native Image 不会在设备 (iOS) 方向更改时调整大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆