【问题标题】:Gesture (Orientation) events not being called in titanium alloy钛合金中未调用手势(方向)事件
【发布时间】:2014-06-23 10:36:13
【问题描述】:

我第一次在钛上开发应用程序并处理方向变化。我正在使用钛合金框架来构建我的应用程序。

我使用视图的方式是:

  1. 我有一个视图,其中有一个导航窗口和一个使用的窗口。

  2. 所有子视图都加载到导航窗口中。

  3. 当我浏览视图时,会自动处理后退导航。

我在模拟器中运行它,当我改变方向时,不会调用方向事件。我不确定它是否被添加。我在这里错过了什么吗?我已经尝试过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


    【解决方案1】:

    您正在为错误的事件名称添加侦听器。没有事件名称onOrientationChanged。你必须使用orientationchange:

    Titanium.Gesture.addEventListener("orientationchanged", function(evt) {
        /* ... */
    });
    

    【讨论】:

    • 它工作...我只是复制了你的代码..所以你写的sn-p有orientationchanged而不是orientationchange。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    相关资源
    最近更新 更多