如何在react-native iOS中获得正确的屏幕宽度?

Law*_*euk 8 width react-native

react-native Dimensions.get("window").宽度为iPhone 6s返回375 ....它似乎远非正确.

`

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Dimensions
} from 'react-native';



class AwesomeProject extends Component {

  render() {
    return <Text style={{margin:50}}>Width: {Dimensions.get("window").width}</Text>;
  }
}
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);`
Run Code Online (Sandbox Code Playgroud)

显然是错的,但没有人在他们的github中报告这个问题,所以我似乎做错了....

Mic*_*vey 19

375是iPhone 6 的分数.对于大多数情况,分数会很好.但是如果你需要像素,你可以使用PixelRatioReact Native提供的API.

例如,要获得iPhone可以使用的渲染像素的距离Dimensions.get('window').width * PixelRatio.get(),iPhone 6的返回值应为750.