【问题标题】:Locking to Portrait on app launching rotates from Landscape to Portrait (iOS)应用程序启动时锁定为纵向从横向旋转到纵向 (iOS)
【发布时间】:2018-11-09 08:28:56
【问题描述】:

我想将应用的第一个屏幕的方向锁定为纵向。在某些屏幕中,我需要横向。我正在使用react-native-orientation 插件。但是当我启动应用程序时,我看到一段时间是横向的,然后快速旋转到纵向。下一个屏幕没问题。

这是我的代码:

componentDidMount() {
    Orientation.lockToPortrait();
}

有没有可能解决这个性能问题?

【问题讨论】:

  • 您要禁用应用中所有屏幕的横向显示吗?
  • @Nino9612 不,在某些屏幕中我需要横向显示。
  • 嗯好的。您正在为哪些平台开发?
  • @Nino9612 适用于 iOS 和 Android。但是这个问题只存在于iOS中。
  • 你试过Orientation.lockToPortrait()之外的组件生命周期方法可能在app.js吗?

标签: ios react-native


【解决方案1】:

在延迟锁定方向的页面中添加以下代码:

componentWillMount(){
    Orientation.lockToPortrait();
    Orientation.addOrientationListener(this._orientationDidChange);
}

_orientationDidChange(orientation) {    
    Orientation.lockToPortrait();  
}

componentWillUnmount() {
    // remove listener
    Orientation.removeOrientationListener(this._orientationDidChange);
}

【讨论】:

  • 没有帮助。
【解决方案2】:

react-native-orientation 似乎不再维护。

我鼓励您使用react-native-orientation-locker,它还提供Orientation.lockToPortrait()

【讨论】:

  • 结果与 react-native-orientation 相同。
  • 你的设备是什么?你的操作系统版本号是多少?
  • 我的设备是 iPhone SE。 iOS 12.0.1。
【解决方案3】:

这是我的错误。 我在一类中使用了冗余代码:

const setLandscapeRightOrientation = Platform.select({
    ios: Orientation.lockToLandscapeRight(),
    android: Orientation.lockToLandscapeLeft(),
});

【讨论】:

    猜你喜欢
    • 2015-05-18
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多