【问题标题】:Titanium: How to determine the screen width when using SplitView?Titanium:使用SplitView时如何确定屏幕宽度?
【发布时间】:2017-09-24 23:37:54
【问题描述】:

我习惯于在我的应用程序中使用Titanium.Platform.displayCaps.platformWidth 来获取窗口的宽度。

但使用 iPad 上的 SplitView Titanium.Platform.displayCaps.platformWidth 仍会返回 iPad 的总屏幕尺寸(可能应该如此)。

在使用 SplitView 时如何确定应用的实际可用屏幕宽度?

我不是说 SplitWindow 顺便说一句。这是关于 SplitView,您可以在 iPad 上将两个不同的应用程序并排排列

谢谢!

【问题讨论】:

    标签: titanium appcelerator titanium-mobile appcelerator-titanium


    【解决方案1】:

    您可以使用 postLayout 事件获取 uiElement 的宽度

    var uiWidth;
    myElement.addEventListener('postlayout', postlayout);
    function postlayout(e){
        uiWidth = e.source.rect.height;
        myElement.removeEventListener('postlayout', postlayout);
    }
    

    【讨论】:

      【解决方案2】:

      确定某个视图的宽度的一种简单方法是在 UI 元素上使用toImage(),然后获取大小。

      所以...当你这样做时

      console.log($.myWindow.toImage().rect.width);
      

      你应该得到窗口的宽度。这应该是分配给您的应用的宽度。

      【讨论】:

      • 这非常消耗内存,我不会在每次调整大小时对整个窗口执行 toImage()。另一个答案完美无缺。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      • 1970-01-01
      • 2021-03-17
      • 1970-01-01
      • 1970-01-01
      • 2023-01-01
      • 1970-01-01
      相关资源
      最近更新 更多