在应用启动时锁定为人像从风景旋转为人像(iOS)

时间:2018-11-09 08:28:57

标签: ios react-native

我想将应用程序的第一个屏幕的方向锁定为纵向。在某些屏幕上,我需要横向放置。我正在使用react-native-orientation插件。但是,当我启动该应用程序时,我会看到一段时间的横向,然后迅速旋转为纵向。接下来的屏幕可以。

这是我的代码:

componentDidMount() {
    Orientation.lockToPortrait();
}

是否可以解决此性能问题?

3 个答案:

答案 0 :(得分:1)

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

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

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

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

答案 1 :(得分:0)

react-native-orientation似乎不再保持。

我建议您使用react-native-orientation-locker,它也提供Orientation.lockToPortrait()

答案 2 :(得分:0)

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

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