代码之家  ›  专栏  ›  技术社区  ›  Oliver84

尺寸。获取(“屏幕”)。width在iPad模拟器中返回错误的宽度?

  •  1
  • Oliver84  · 技术社区  · 8 年前

    Dimensions.get('screen').width 返回的宽度为 320 iPad simulator .

    320 x 480屏幕和窗口分辨率

    .

    3 回复  |  直到 8 年前
        1
  •  1
  •   Oliver84    8 年前

    多亏了@Dani Akash,我想我找到了一个解决方案,可以解决我在这里要做的事情。 React Native: How to Determine if Device is iPhone or iPad

    import { Dimensions } from 'react-native';
    const {height, width} = Dimensions.get('window'); 
    const aspectRatio = height/width;
    
    if(aspectRatio>1.6) {
    
       // Code for Iphone
    
    }
    else {
    
       // Code for Ipad
    
    }
    
        2
  •  0
  •   Val    8 年前

    反应本机宽度和;高度为 密度无关像素

    为什么使用 density-independent pixels

    以这种方式设置尺寸对于应该 无论屏幕大小如何,始终以完全相同的大小渲染 尺寸。

    Layout with Flexbox .

        3
  •  0
  •   steffeydev    8 年前

    我知道这是事后,但你也可以用 react-native-device-info