滑动手势不会轻扫容器

时间:2014-09-15 02:38:31

标签: javascript ios titanium-mobile titanium-alloy

我正在尝试刷一个容器,它的子元素离开屏幕。但是,当我运行以下代码时,我滑动的子元素离开屏幕而不是两个元素。

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
    title : 'Tab 1',
    backgroundColor : '#fff'
});

var viewContainer = Titanium.UI.createImageView({
    backgroundColor : 'white',
    width : '100%',
    height : '100%',
    top : 0
});

var view = Titanium.UI.createImageView({
    backgroundColor : 'green',
    width : '100%',
    height : '100%',
    top : 0
});

var view1 = Titanium.UI.createView({
    backgroundColor : 'red',
    width : '100%',
    height : 100,
    bottom : 0
});


viewContainer.addEventListener('swipe', function(e) {

    if (e.direction == "right") {

        //TODO: add functionality here

    } else if (e.direction == "left") {

        var anim = Ti.UI.createAnimation({

            left : -300,
            duration : 200,
            curve : Ti.UI.ANIMATION_CURVE_EASE_OUT
        });

        anim.addEventListener('start', function(_startanicallback) {

        });

        anim.addEventListener('complete', function(_anicallback) {

        });

        e.source.animate(anim);
    }

});

viewContainer.add(view);
viewContainer.add(view1);
win1.add(viewContainer);
win1.open();

我有一个:

ViewContainer - 也附加了事件监听器。

在其中,查看和查看两个子元素。

不确定为什么会这样。

干杯。

1 个答案:

答案 0 :(得分:1)

只有一个元素被刷过的原因是这一行: e.source.animate(anim);

如果您将其替换为viewContainer.animate(anim);,则滑动将按您的意愿使用。

希望它有所帮助。

相关问题