Flutter:无法更改 Ipad 上的设备方向

agu*_*oll 6 mobile android ios flutter

完整日志:无法更改设备方向:错误域=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,
    ]);
  }
Run Code Online (Sandbox Code Playgroud)

我尝试以编程方式更改设备方向,但没有成功,正在 android 和 Iphone 模拟器上工作,但不在真正的 Ipad 上。

Fel*_*ski 0

iPad 方向锁定

默认情况下,iPad 允许多任务处理,并且其方向无法锁定。如果您需要在 iPad 上锁定方向,请将以下内容添加到 Info.plist,将选项“需要全屏”设置为“是”:

<key>UIRequiresFullScreen</key>
<true/>
Run Code Online (Sandbox Code Playgroud)

摘自:https: //capacitorjs.com/docs/apis/screen-orientation

也许它也会帮助我的颤振兄弟:)