是否有一种方法可以通过编程方式检测是否在Xamarin中启用了舞台管理器?

rxztt3cl  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(140)

我正在做一个概念验证,看看我是否可以通过编程方式停用iPad应用的Stage Manager功能。这是iOS 16测试版的一部分。下面是我开始关注的两个方面
1.检测舞台管理器是否已启用
1.查看是否有禁用舞台管理器功能的方法
在阅读了很多文章之后,我无法找出Xamarin中的任何API来帮助我检测舞台管理器是否被激活。我尝试了下面的代码片段,但这似乎没有给我正确的结果。

var appWindow = application
            .ConnectedScenes
            .ToArray()
            .OfType<UIWindowScene>()
            .SelectMany(scene => scene.Windows)
            .FirstOrDefault(window => window.IsKeyWindow);

 var screenHeight = appWindow.Window.WindowScene.Screen.Bounds.Height;
 var windowHeight = appWindow.Window.Screen.Bounds.Height;
 bool stageManager = screenHeight > windowHeight;

上面的代码片段来自我在搜索API时找到的一篇参考文章

var isStageManager: Bool {
    guard UIDevice.current.userInterfaceIdiom == .pad,
       let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate,
       let screenHeight = sceneDelegate.window?.windowScene?.screen.bounds.height,
       let windowHeight = sceneDelegate.window?.bounds.height else { return false }
    return screenHeight > windowHeight
  }

注意:尝试更改screenHeight/windowHeight的检索方式,如下所示。但是,尽管舞台管理器已启用,但检索到的两个变量的值相同。有人尝试过这样做吗?或者有任何参考资料可以帮助我更接近解决方案吗?

var screenHeight = appWindow.WindowScene.Screen.Bounds.Height;
var windowHeight = appWindow.Screen.Bounds.Height;
7hiiyaii

7hiiyaii1#

你可以试试看是否有帮助:

var sceneDelegate = UIApplication.SharedApplication
            .ConnectedScenes
            .ToArray()
            .FirstOrDefault()
            .Delegate as SceneDelegate;

var screenHeight = sceneDelegate.Window.WindowScene.Screen.Bounds.Height;
var windowHeight = sceneDelegate.Window.Bounds.Height;
bool stageManager = screenHeight > windowHeight;

相关问题