【问题标题】:Locking the screen orientation per screen in Flutter does not work on iPad在 Flutter 中锁定每个屏幕的屏幕方向在 iPad 上不起作用
【发布时间】:2022-10-24 06:21:18
【问题描述】:

我正在开发一个应用程序,根据它是哪个屏幕将屏幕方向锁定为纵向或横向。 IE。我有一个使用纵向模式的设置流程,但完成并启动“应用程序”后,我切换到横向模式。

无论如何,每个屏幕锁定代码(在谷歌搜索时推荐)在我的 iPhone 上运行良好,但在我的 iPad 上却不起作用。

在 iPad 上,屏幕会旋转并变黑。

锁定设置屏幕的代码:

  @override
  void initState() {
    super.initState();
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
      DeviceOrientation.portraitDown,
    ]);
  }

是的,我已经做到了

 WidgetsFlutterBinding.ensureInitialized();

【问题讨论】:

    标签: flutter ipad screen-orientation


    【解决方案1】:

    我终于通过手动编辑 Info.plist 文件来修复它。

    使用文本编辑器打开它并更改您找到的支持的方向值:

    <key>UISupportedInterfaceOrientations</key>
    <array>
    <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
    <string>UIInterfaceOrientationPortrait</string>
    </array>
    

    第一个块用于 iPhone,第二个块用于 iPad(这将阻止多任务处理)

    【讨论】:

      猜你喜欢
      • 2022-07-05
      • 2018-01-19
      • 1970-01-01
      • 2021-11-21
      • 2011-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      相关资源
      最近更新 更多