繁体   English   中英

LandScape不能在React Native中工作吗? 当IOS / Android设备关闭模式自动旋转时

[英]LandScape not Working in React native ? when IOS / Android Device off mode Auto Rotation

我正在基于本机响应方向开发示例应用程序。 实际上定向是可行的。 我要在进入特定页面时使用风景模式。在这种情况下可以正常显示风景模式,但是当我尝试将设备转到人像模式时。但是当我将肖像或风景转向时,我只想显示风景而不是肖像。

我正在使用此模块并编写以下代码:

var Orientation = require('react-native-orientation');

class XOrating extends React.Component {
   constructor(props){
    super(props);
    this.state={

       HEIGHT:667,
       WIDTH:375


    }
  }

componentWillMount(){

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

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


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

}

 _orientationDidChange(orientation) {
    if (orientation == 'LANDSCAPE') {

      Orientation.lockToLandscape();
      //do something with landscape layout
    } else if(orientation == 'PORTRAIT') {
      //do something with portrait layout   
       Orientation.lockToLandscape();
    }
  }

   componentWillUnmount() {
    Orientation.getOrientation((err,orientation)=> {
      console.log("Current Device Orientation: ", orientation);
    });
    Orientation.removeOrientationListener(this._orientationDidChange);
  }


componentDidMount(){


    Orientation.addOrientationListener(this._orientationDidChange);

 }

render(){
return(
<Image source={{uri:this.state.ImgBackground}} style={{width:this.state.WIDTH,
              height:this.state.HEIGHT, top:0, left:0}}>   
)
}

module.exports = XOrating;

在自动旋转隐藏在设备中时,请建议我要适合横向模式

是的,最后我得到了我正在做的错误.....

只是我在AppDelegate.m文件中同时添加了两行,然后在下一步清洁x代码并运行。

#import "../../node_modules/react-native-orientation/iOS/RCTOrientation/Orientation.h"


 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    return [Orientation getOrientation];
  }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM