简体   繁体   English

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

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

I am developing sample app based on react native orientation. 我正在基于本机响应方向开发示例应用程序。 Actually orientation is working. 实际上定向是可行的。 i want landscape mode when i was go to one particular page.it's ok no problem at this situation shows landscape mode, but when i am trying device turn to Portrait mode.but when i am turn Portrait or Landscape i want show only landscape not a portrait. 我要在进入特定页面时使用风景模式。在这种情况下可以正常显示风景模式,但是当我尝试将设备转到人像模式时。但是当我将肖像或风景转向时,我只想显示风景而不是肖像。

I am Using this module and wrote this code: 我正在使用此模块并编写以下代码:

var Orientation = require('react-native-orientation'); 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;

Please suggest i want fit the landscape mode when hide in device in autorotation 在自动旋转隐藏在设备中时,请建议我要适合横向模式

Yes Finally I got a what i am doing my mistake..... 是的,最后我得到了我正在做的错误.....

Just i add both two lines in AppDelegate.m file and after next clean the x code and run. 只是我在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.

相关问题 适用于风景模式ios和android的React-Native不同视图 - React-Native Different View for Landscape Mode ios and android 当远程调试器关闭时,Reos本机在ios设备上运行缓慢 - React native runs slow on ios device when remote debugger is off 如何在 React Native Android 开发模式下禁用横向模式? - How to disable landscape mode in React Native Android dev mode? React原生抽屉(适用于iOS和Android)禁用/ drawerLock模式无法正常工作 - React native drawer (for iOS & Android) disable/drawerLock mode not working 如何确定景观反应本机的旋转 - How to determine rotation of landscape react-native React-Native iOS 热重载和调试模式在真实设备中不起作用 - React-Native iOS hot reloading and debug mode not working in real device 下载图像在 IOS 设备上不起作用 - React Native - Download image not working on IOS device - React Native React Native:仅在webview播放视频时允许设备轮换 - React Native: Allow device rotation only when webview plays video React Native 在 Android 设备上崩溃,但在 iOS 上工作 - React Native crashes on Android device but works on iOS React Native - 当应用程序不在后台(Android,iOS)时,深度链接不起作用 - React Native - Deep linking is not working when app is not in background (Android, iOS)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM