我使用反应-本机维度来获取屏幕的尺寸,并确定用户是在纵向还是横向,mode.....however Dimensions.get('screen').height总是作为两面中较长的一方回来,即使在景观模式下也是如此。Dimensions.get('screen').height总是比Dimensions.get('screen').width大,即使在景观模式下也是如此。
constructor(props) {
super(props);
this.state = {
orientation: (Dimensions.get('screen').height >= Dimensions.get('screen').width ? 'portrait' : 'landscape')
};
Dimensions.addEventListener('change', () => {
let orientation = (Dimensions.get('screen').height >= Dimensions.get('screen').width ? 'portrait' : 'landscape');
this.setState({
orientation: orientation
});
});
}发布于 2021-04-10 09:34:29
使用useWindowDimensions()。只需将类似的内容放在根组件中:
const SCREEN_WIDTH = useWindowDimensions().width;
const SCREEN_HEIGHT = useWindowDimensions().height;
return (
<View style={{ width: SCREEN_WIDTH, minHeight: SCREEN_HEIGHT}} >
//the rest of your app
</View>
);https://stackoverflow.com/questions/67030717
复制相似问题