【发布时间】:2014-06-23 10:36:13
【问题描述】:
我第一次在钛上开发应用程序并处理方向变化。我正在使用钛合金框架来构建我的应用程序。
我使用视图的方式是:
我有一个视图,其中有一个导航窗口和一个使用的窗口。
所有子视图都加载到导航窗口中。
当我浏览视图时,会自动处理后退导航。
我在模拟器中运行它,当我改变方向时,不会调用方向事件。我不确定它是否被添加。我在这里错过了什么吗?我已经尝试过Titanium.Gesture.isPortrait() 和Titanium.Gesture.isLandscape(),但无济于事。
下面是代码,父窗口是这样的:
<Alloy>
<NavigationWindow id="challengeNav">
<Window title="Mobile Mentor" onOpen="loadChallenges" class="container" barColor="#003363" fullscreen="true">
<!-- Controls -->
</Window>
</NavigationWindow>
</Alloy>
我正在使用方向更改的子视图如下所示:
<Window class="container" title="Challenge Video" barColor="#003363" onOpen="addGestureChangeEvent" fullscreen="true">
<RightNavButton>
<Button title="Next" onClick="recordResponse" />
</RightNavButton>
<View id= "videoContainer">
<VideoPlayer id="challengeVideoPlayer" ns="Ti.Media" autoplay="false" volume="1" scalingMode="Titanium.Media.SCALING_ASPECT_FILL" />
</View>
</Window>
子视图的 JS 控制器是:
var args = arguments[0] || {};
var currUser = Alloy.Globals.CurrentUser;
var challengeNav = Alloy.Globals.ChallengeNavParent;
var orientation = Titanium.Gesture.orientation;
var challengeData = args;
$.challengeVideoPlayer.url = challengeData.Challenge.VideoUrl;
$.txtOptionalTip.value = challengeData.Challenge.OptionalTip != undefined ? challengeData.Challenge.OptionalTip : "Optional Tip not available";
function addGestureChangeEvent(e) {
}
Titanium.Gesture.addEventListener("onOrientationChanged", function(evt) {
alert("Gesture Change");
orientation = Titanium.Gesture.orientation;
if (orientation === 3 || orientation === 4) {
alert("Gesture Change Landscape");
$.challengeVideoPlayer.fullscreen = true;
} else {
alert("Gesture Change Portrait");
$.challengeVideoPlayer.fullscreen = false;
}
});
function recordResponse(e) {
$.challengeVideoPlayer.stop();
//$.challengeVideoPlayer.release(); //This code releases the internal video resource of the video player.
var challengeResponseController = Alloy.createController("challengeResponse", challengeData).getView();
challengeNav.openWindow(challengeResponseController);
}
【问题讨论】:
标签: ios iphone titanium-mobile titanium-alloy