[英]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.