react native 设置屏幕锁定

原生配置

        android 在android/app/src/main/AndroidManifest.xml在这个文件里的入口activity里添加

android:screenOrientation="portrait"

 <activity
        android:name=".MainActivity"
        android:label="@string/app_name"                               android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:screenOrientation="portrait"
        android:exported="true"
>

iOS在AppDelegate.mm文件里加上一下代码

- (void)setOrientationLock {
    // 设置竖屏锁定
    [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
}

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return UIInterfaceOrientationMaskPortrait;
}

第三方包

react-native-orientation-locker

先按照文档里配置,以下是用法示例:

  componentWillMount() {
    //横屏
    Orientation.lockToLandscape();
  }
  componentWillUnmount() {
    //页面销毁后恢复竖屏
    Orientation.lockToPortrait();
  }

具体用法可以去文档去查。

相关推荐

  1. react native 设置屏幕锁定

    2024-05-11 02:02:02       15 阅读
  2. react 屏幕信息滚动

    2024-05-11 02:02:02       11 阅读
  3. adb多设备屏幕调试

    2024-05-11 02:02:02       9 阅读
  4. OpenHarmony及鸿蒙应用的屏幕亮度获取以及设置

    2024-05-11 02:02:02       9 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-11 02:02:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-11 02:02:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-11 02:02:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-11 02:02:02       20 阅读

热门阅读

  1. python学习之argparse模块

    2024-05-11 02:02:02       12 阅读
  2. VirtualBox虚拟FreeBSD15显卡配置@Win10

    2024-05-11 02:02:02       12 阅读
  3. Redis缓存篇

    2024-05-11 02:02:02       9 阅读
  4. Day35 无重叠区间 + 划分字母区间 + 合并区间

    2024-05-11 02:02:02       12 阅读
  5. Nginx-那些事

    2024-05-11 02:02:02       14 阅读
  6. 【GoLang基础】垃圾回收是如何工作的?

    2024-05-11 02:02:02       11 阅读
  7. 关于emulate

    2024-05-11 02:02:02       11 阅读
  8. 7-Zip命令行调用命令收集(20个)

    2024-05-11 02:02:02       12 阅读
  9. 如何找到高质量的微信群?分享8种适用的方法!

    2024-05-11 02:02:02       11 阅读
  10. 如何利用AI提高内容生产效率?

    2024-05-11 02:02:02       8 阅读