【问题标题】:Is there a way to programmatically detect if Stage Manager is enabled in Xamarin?有没有办法以编程方式检测是否在 Xamarin 中启用了 Stage Manager?
【发布时间】:2022-10-24 08:29:58
【问题描述】:

我正在开发 POC,以查看是否可以通过编程方式停用 IPAD 应用程序的 Stage Manager 功能。这是 iOS 16 测试版的一部分。以下是我开始关注的两个领域

  1. 检测 Stage Manager 是否已启用
  2. 查看是否有方法可以禁用 Stage Manager 功能

    在浏览了很多文章之后,我无法找出 Xamarin 中的任何 API 可以帮助我检测 Stage Manager 是否已激活。我尝试了下面的代码 sn-p,但这似乎并没有给我正确的结果。

     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;                
            
    

    上面的 sn-p 来源于我在搜索 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;
    

【问题讨论】:

  • 即使您可以检测到它,我认为没有任何方法可以以编程方式禁用它
  • 谢谢,杰森的回应。我编码检测它的方式有什么问题吗?

标签: c# xamarin xamarin.ios ios16


【解决方案1】:

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

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-28
    • 2011-07-18
    • 2011-11-09
    • 2014-12-22
    • 2014-02-15
    • 1970-01-01
    相关资源
    最近更新 更多