英文:
Screen orientation not locking on iOS
问题
我是新手使用 Expo Go React Native,并在屏幕方向方面遇到了问题。在我的 Expo Go React Native 项目中,我有:
import * as ScreenOrientation from 'expo-screen-orientation';
export default app = () => {
async function changeScreenOrientation() {
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
}
changeScreenOrientation();
return (剩余的代码部分)
};
这个函数允许我旋转设备并切换方向。但是它不会排除纵向方向。最近,在 Expo Go 更新其应用程序之前,方向从未切换到纵向。
有其他人也遇到同样的问题吗?
我尝试过 react-native-screen-orientation
- 返回: "找不到 null 属性"。
我也尝试过 expo-screen-orientation。
英文:
I'm new to expo go react native and bumped into a problem within screen-orientation. In my expo go react native project I have:
import * as ScreenOrientation from 'expo-screen-orientation';
export default app = () => {
async function changeScreenOrientation() {
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
}
changeScreenOrientation();
return(restofcode)
};
The function allows me to rotate the device, and switch orientation. However it wont exclude portrait orientation. Recently, before expo go updated its app, the orientation never switched to portrait.
Anybody else experiencing the same issue?
I have tried react-native-screen-orientation
- returned: "Cannot find property of null"
I have tried expo-screen-orientation
答案1
得分: 1
在 app.json 中检查是否存在这行内容:"orientation": "portrait",如果存在则删除它。此外,似乎 iOS 特定存在一个问题,与 "expo-screen-orientation" 相关,解决方法似乎是在使用 ScreenOrientation 之前使用 ScreenOrientation.unlockAsync()。具体讨论可以查看这个链接:https://github.com/expo/expo/issues/23368。
英文:
in app.json check if this line is present "orientation": "portrait", if it is remove it. Also there seems to be a bug for iOS specifically for "expo-screen-orientation" and workaround seems to be to use ScreenOrientation.unlockAsync() before doing anything with ScreenOrientation.
Here is where it is being discussed https://github.com/expo/expo/issues/23368
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论