【问题标题】:How to simply handle orientation changes?如何简单地处理方向变化?
【发布时间】:2011-07-16 10:06:20
【问题描述】:

我不是在谈论做任何花哨的事情。我只想在用户旋转设备时旋转标准窗口和视图。

【问题讨论】:

    标签: titanium appcelerator appcelerator-mobile


    【解决方案1】:
    Titanium.Gesture.addEventListener('orientationchange', function(e) {
        Titanium.API.info('Gesture Change Detected');
        Ti.App.fireEvent('orientationchange', {eventObject:e});
    });
    

    【讨论】:

    • 所以 - 必须接受该事件,然后重新触发它,以便显示旋转?
    • 这是一种用于在我的每个视图中划分方向更改功能的方法。您不必重新触发事件
    【解决方案2】:

    你需要告诉窗口它应该支持哪些方向:

    var window = Ti.UI.createWindow({
        orientationModes: [
            Ti.UI.LANDSCAPE_LEFT,
            Ti.UI.LANDSCAPE_RIGHT,
            Ti.UI.PORTRAIT,
            Ti.UI.UPSIDE_PORTRAIT
        ]
    });
    
    window.open();
    

    然后您可以像这样使用监听器来监听方向变化:

    Ti.Gesture.addEventListener('orientationchange', function(e) {
        Titanium.API.info('Orientation changed');
    });
    

    编辑:我认为(虽然我从未尝试过)你也可以在 tiapp.xml 中设置它,它具有自动应用于所有窗口的额外好处。

    <orientations device="iphone">
        <orientation>Ti.UI.LANDSCAPE_LEFT</orientation>
        <orientation>Ti.UI.LANDSCAPE_RIGHT</orientation>
        <orientation>Ti.UI.PORTRAIT</orientation>
        <orientation>Ti.UI.UPSIDE_PORTRAIT</orientation>
    </orientations>
    

    【讨论】:

    • 我认为您对 tiapp.xml 配置更改是正确的。这就是我一直在寻找的。​​span>
    【解决方案3】:

    这是在 android 默认情况下工作的。但不能在iphone上工作,所以只需编写这段代码

    var win1 = Ti.UI.createWindow({
       title : 'Tab 1',
     orientationModes: [
            Ti.UI.LANDSCAPE_LEFT,
            Ti.UI.LANDSCAPE_RIGHT,
            Ti.UI.PORTRAIT,
            Ti.UI.UPSIDE_PORTRAIT
        ],
    });
    
    win1.open();
    
    Ti.Gesture.addEventListener('orientationchange', function(e) {
        Titanium.API.info(Ti.Gesture.orientation);
    });
    

    我认为这对你有用。

    【讨论】:

      猜你喜欢
      • 2013-07-11
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-03
      • 1970-01-01
      • 2011-04-11
      相关资源
      最近更新 更多