【发布时间】:2021-10-06 00:13:57
【问题描述】:
我是反应原生的新手。我陷入了一个问题,是否可以在 react-native 中锁定 Landscape 中的特定屏幕?换句话说,我们可以为特定屏幕配置屏幕方向吗?
帮我解决这个问题?
【问题讨论】:
标签: react-native orientation fullscreen screen-orientation
我是反应原生的新手。我陷入了一个问题,是否可以在 react-native 中锁定 Landscape 中的特定屏幕?换句话说,我们可以为特定屏幕配置屏幕方向吗?
帮我解决这个问题?
【问题讨论】:
标签: react-native orientation fullscreen screen-orientation
您可以使用react-native-orientation 或react-native-orientation-locker。
https://www.npmjs.com/package/react-native-orientation https://www.npmjs.com/package/react-native-orientation-locker
React 本机方向提供了以下 API,有助于实现屏幕方向
Orientation.lockToPortrait()
Orientation.lockToLandscape()
Orientation.lockToLandscapeLeft()
Orientation.lockToLandscapeRight()
Orientation.unlockAllOrientations()
Orientation.getOrientation((err, orientation) => {})
Orientation.getSpecificOrientation((err, specificOrientation) => {})
请检查以下代码sn-p
import Orientation from 'react-native-orientation'
componentDidMount() {
Orientation.unlockAllOrientations();
}
componentWillUnmount() {
Orientation.lockToPortrait();
}
【讨论】: