简体   繁体   English

滑动手势不会将容器滑出

[英]Swipe gesture not swiping container off

I am trying to swipe a container and it's children elements off the screen. 我正在尝试滑动一个容器,它是屏幕上的子元素。 However when I run the following code, the child element I swipe goes off the screen as opposed to both elements. 但是,当我运行以下代码时,与两个元素相反,我滑动的子元素从屏幕上消失了。

// 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();

I have a : 我有一个 :

ViewContainer - where the event listener is attached too. ViewContainer-事件侦听器也附加在其中。

Inside that , view and view1 both child elements. 在that内,view和view1都是两个子元素。

Not sure why this is happening. 不知道为什么会这样。

Cheers. 干杯。

The reason for only one of the elements being swiped is this line : e.source.animate(anim); e.source.animate(anim);其中一个元素的原因是此行: e.source.animate(anim);

If you will replace it with viewContainer.animate(anim); 如果将其替换为viewContainer.animate(anim); the swipe will work as you want. 滑动即可根据需要工作。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM