【问题标题】:React native disable auto rotate [duplicate]反应本机禁用自动旋转[重复]
【发布时间】:2017-09-29 09:59:23
【问题描述】:

我需要在 react-native 应用程序中禁用自动旋转功能。

应用程序应该支持纵向和横向,但用户不能旋转屏幕。现在我使用了 react-native-orientation 但这个模块只检查了方向并将其更改为必要的值。

所以我只需要以编程方式旋转屏幕。

RN 版本:0.33

【问题讨论】:

  • 没有。我应该支持纵向和横向,所以我不能在 Xcode 上禁用这个方向。
  • 我似乎无法理解您的问题是什么。请发布您到目前为止所做的工作

标签: ios reactjs react-native screen-orientation


【解决方案1】:

您可以设置 Xcode 设备方向

在您的 android 清单文件中设置: android:screenOrientation="portrait"

或者您可以使用Dimensions 进行设置。像这样的:

Dimensions.addEventListener('change', ({ window: { width, height } }) => {
    const orientation = width > height ? 'LANDSCAPE' : 'PORTRAIT';
}

或者您可以根据需要使用react-native-orientation 将屏幕锁定为纵向或横向。我的 github 中有一个工作示例:https://github.com/soutot/react-native-orientation-test

class App extends Component {
    componentDidMount() {
        Orientation.lockToLandscape();
    }

    render() {
        return(
            <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center'}}>
                <Text>This is my content</Text>
            </View>
        );
    }
}

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多