【问题标题】:Orientation issue in react native反应原生的方向问题
【发布时间】:2017-02-15 06:19:32
【问题描述】:

我正在使用 React 原生定向模块。我只需要一个屏幕的横向视图。所以在 componentDidMount() 中写了 loackToLandscape() ,回去的时候我写了 lockToProtrait()。

我的代码如下:

componentWillMount(){

  if(this.props.sportName == 'Pro Football'){
    Orientation.lockToLandscape();

    this.setState({
      HEIGHT:375,
      WIDTH:667


    })
  }
  else{
   Orientation.lockToPortrait();
  }

}
onBack(){
  Orientation.lockToPortrait();
       this.setState({
        open:false
      })
  }

autorotation 为 false 时,它​​工作正常。但是,当我将设备更改为纵向时 autorotation 打开时,视图也会更改为纵向。但我希望它被锁定为横向。

【问题讨论】:

    标签: reactjs react-native orientation


    【解决方案1】:

    只是你必须试试这个:

    在 AppDelegate.m 中添加两行

    #import "../../node_modules/react-native-orientation/iOS/RCTOrientation/Orientation.h"
    
     - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
        return [Orientation getOrientation];
      }
    

    在您点击此链接之前,您将获得结果:

    首先你是按照链接如何锁定到横向

    https://github.com/yamill/react-native-orientation

    【讨论】:

      猜你喜欢
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      相关资源
      最近更新 更多