[英]How to lock orientation in some views in Titanium app
I'm doing an application for Android and IOS. 我正在为Android和IOS开发应用程序。 In this application, I have a window, and I add/remove different views with the content.
在此应用程序中,我有一个窗口,并在内容中添加/删除了不同的视图。
I want that the first view will be only in portrait mode, whereas the rest of the views can be in any orientation. 我希望第一个视图仅处于纵向模式,而其余视图可以处于任何方向。
How can I do it? 我该怎么做?
With titanium SDK 3.1.2 it works more or less on IOS: 使用Titan SDK 3.1.2,它或多或少在IOS上起作用:
My window: 我的窗口:
var appWindow = Titanium.UI.createWindow({
top : 0,
left : 0,
height : utils.getScreenHeight(),
width : utils.getScreenWidth(),
backgroundColor : "#393a3a",
//fullscreen : true,
orientationModes : [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT],
});
Then, when I want to load a view: 然后,当我想加载视图时:
var openWindow = function(e) {
appWindow.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];
if (e.win == 'Home') {
Titanium.UI.orientation = Titanium.UI.PORTRAIT;
appWindow.orientationModes = [Titanium.UI.PORTRAIT];
orientacion = 0;
activeView = Home.Constructor(appWindow);
} else if (e.win == 'configuracion') {
Titanium.UI.orientation = Titanium.UI.PORTRAIT;
orientacion = 0;
appWindow.orientationModes = [Titanium.UI.PORTRAIT];
activeView = Configuracion.Constructor(appWindow);
} else if (e.win == 'Circle') {
activeView = Circle.Constructor(appWindow);
}
appWindow.add(activeView);
};
Now, I want to use SDK 3.1.3 to support IOS 7, and it doesn't work, none of the views allow to rotate. 现在,我想使用SDK 3.1.3来支持IOS 7,并且它不起作用,所有视图都无法旋转。
Do you know how I can do this? 你知道我该怎么做吗?
Thank you very much 非常感谢你
I did not have any luck with changing a windows orientationModes on runtime too. 我也没有在运行时更改WindowsdirectionModes的运气。 The docs say that the window property
orientationModes
as well as its method setOrientationModes
have to be set before opening the window. 该文件说,该窗口属性
orientationModes
以及其方法setOrientationModes
有打开的窗口前设置。
So switching from views to windows is not an option? 那么从视图切换到窗口不是一种选择吗?
If you want a window to allow orientations different from those defined in tiapp.xml, you have to set orientationModes on every window individually: 如果希望窗口允许与tiapp.xml中定义的方向不同的方向,则必须分别在每个窗口上设置directionModes:
// This window allows orientations defined in tiapp.xml
var appWin = Ti.UI.createWindow({
backgroundColor = '#FFF'
});
appWin.open();
// This window is portrait only
var win = Ti.UI.createWindow({
backgroundColor: '#FFF',
orientationModes: [Ti.UI.PORTRAIT]
});
win.open();
// If this window is opened it allows multiple orientations
var newWindow = Ti.UI.createWindow({
backgroundColor: '#FFF',
orientationModes: [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]
});
newWindow.open()
This is tested with SDK 3.1.3. 这已通过SDK 3.1.3进行了测试。
Edit 编辑
To make this work on Android, you have to force a heavyweight window by either setting fullscreen: true
or navBarHidden: true
要在Android上执行此操作,您必须通过设置
fullscreen: true
或navBarHidden: true
来强制设置一个重量级窗口
With titanium SDK 3.1.2 I put the following code for: 使用Titan SDK 3.1.2,我将以下代码用于:
Titanium.UI.orientation = Titanium.UI.PORTRAIT;
appWindow.orientationModes = [Titanium.UI.PORTRAIT];
and then, when you load other view, then put: 然后,当您加载其他视图时,然后输入:
appWindow.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.UPSIDE_PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.