完整日志: 无法更改设备方向:错误域=UISceneErrorDomain代码=101“当前窗口模式不允许以编程方式更改界面方向。” UserInfo={NSLocalizedDescription=当前窗口模式不允许以编程方式更改界面方向。}
void _toggleFullScreen() async {
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
await SystemChrome.setPreferredOrientations(const [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
void _togglePortrait() async {
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
await SystemChrome.setPreferredOrientations(const [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
我尝试以编程方式更改设备方向,但没有成功,正在 Android 和 Iphone 模拟器上工作,但不能在真正的 Ipad 上工作。
默认情况下,iPad 允许多任务处理,并且其方向无法锁定。如果您需要在 iPad 上锁定方向,请将以下内容添加到 Info.plist,将选项“需要全屏”设置为“是”:
UI 需要全屏
摘自: https://capacitorjs.com/docs/apis/screen-orientation
也许它也会帮助我的扑扑兄弟:)