簡體   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