6

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

4

3 回答 3

10

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

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>
于 2011-03-16T12:16:06.590 回答
1

这是在 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);
});

我认为这对你有用。

于 2012-03-07T10:52:37.080 回答
1
Titanium.Gesture.addEventListener('orientationchange', function(e) {
    Titanium.API.info('Gesture Change Detected');
    Ti.App.fireEvent('orientationchange', {eventObject:e});
});
于 2011-03-16T11:07:32.267 回答