【问题标题】:How to support different resolutions in titanium Alloy XML如何在钛合金 XML 中支持不同的分辨率
【发布时间】:2024-05-20 02:00:01
【问题描述】:

我使用的是钛合金框架,问题是我根据iphone 5设置了尺寸参数。当我为iphone 4编译时,UI出现了某种干扰。

简而言之,我想要在 iphone 4 和 5 中处理钛合金中 .tss.xml 文件中不同屏幕分辨率的方法。

【问题讨论】:

    标签: ios iphone titanium titanium-alloy


    【解决方案1】:

    您可以尝试根据以下链接设置条件。

    http://developer.appcelerator.com/question/159770/do-we-have-any-conditions-to-handle-in-xml-file#comment-195451

    您可以使用自己的布尔全局变量代替 Alloy.Globals.isIOS7,来检查它是 iphone 4 还是 5。

    【讨论】:

      【解决方案2】:

      @Mitul Bhalia 是正确的。

      1.检测具体屏幕分辨率:

      // app/alloy.js
      Alloy.Globals.isIos7Plus = (OS_IOS && parseInt(Ti.Platform.version.split(".")[0]) >= 7);
      Alloy.Globals.iPhoneTall = (OS_IOS && Ti.Platform.osname == "iphone" && Ti.Platform.displayCaps.platformHeight == 568); 
      

      2.编写查询样式tss:

      // Query styles
      "#info[if=Alloy.Globals.isIos7Plus]" : {
          font : { textStyle : Ti.UI.TEXT_STYLE_FOOTNOTE }
      },
      "#title[if=Alloy.Globals.isIos7Plus]" : {
          top: '25dp', // compensate for the status bar on iOS 7
          font : { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
      },
      "#content[if=Alloy.Globals.isIos7Plus]" : {
          font : { textStyle : Ti.UI.TEXT_STYLE_CAPTION1 }
      },
      "ScrollView[if=Alloy.Globals.iPhoneTall]" : {
          height : '500dp'
      }
      

      参考:http://docs.appcelerator.com/titanium/3.0/#!/guide/Alloy_Styles_and_Themes-section-35621526_AlloyStylesandThemes-Platform-SpecificStyles

      见:https://*.com/a/28298508/445908

      【讨论】: