【发布时间】:2021-07-13 07:06:53
【问题描述】:
My code
<View style={{borderColor:"red",borderWidth:4,flex:1,transform: [{ rotate:'90deg' }]}}>
<Text>Hi</Text>
</View>
这不像我预期的那样工作。视图会旋转,但宽度和高度是根据手机纵向模式计算的,并且视图处于横向模式,这会破坏设计。 我尝试了如下解决方法
import { useWindowDimensions } from 'react-native';
import React, { useState, useEffect,useCallback, useRef } from 'react';
import { Text,View} from "react-native";
const FullScreenMediaPlayer = (props) => {
const windowWidth = useWindowDimensions().width;
const windowHeight = useWindowDimensions().height;
return (
<View style={{width:windowHeight,height:windowWidth,borderColor:"red",borderWidth:4,flex:1,transform: [{ rotate:'90deg' }]}}>
<Text>Hui</Text>
</View>
);
}
export default FullScreenMediaPlayer;
结果: 视图宽度仍然不是屏幕宽度? 如何在横向模式下旋转 View 并使其高度和宽度与屏幕的高度和宽度相同?
PS:我不想使用orientation包我只是想纯粹基于样式来实现这个
【问题讨论】:
-
你想达到什么目的?
-
@LeriGogsadze 我想在不使用方向的情况下将视图更改为横向模式。我在这个视图中有内容
标签: css react-native jsx