正确的执行步骤
1>npm install--savereact-native-orientation
2>react-native link 自动将project和.a文件导入你的xcode 项目中,不需要手动导入
3>bulild,编译运行
iOS:
1.用Xcode打开项目,右键点击项目名称,选择 “Add Files to ‘项目名’ “ ;
2.找到路径文件: 项目文件夹/node_modules/react-native-orientation/RCTOrientation ,将该文件添加上;
3.然后重新运行项目;
Android:
用法
componentWillMount() { // 判断横竖屏幕 var initial = Orientation.getInitialOrientation(); if (initial === 'PORTRAIT') { //do stuff } else { //do other stuff } // 只允许竖屏 Orientation.lockToPortrait(); //只允许横屏 Orientation.lockToLandscape(); } |
Functions
lockToPortrait()
lockToLandscape()
lockToLandscapeLeft()
lockToLandscapeRight()
unlockAllOrientations()
getOrientation(function(err,orientation)
返回的结果有LANDSCAPE
PORTRAIT
UNKNOWN
PORTRAITUPSIDEDOWN
getSpecificOrientation(function(err,specificOrientation)
返回的结果有LANDSCAPE-LEFT
LANDSCAPE-RIGHT
PORTRAIT
UNKNOWN
PORTRAITUPSIDEDOWN
参考:
http://facebook.github.io/react-native/docs/linking-libraries-ios.html#step-3