我正在尝试将容器及其子元素滑出屏幕。但是,当我运行以下代码时,我滑动的子元素会离开屏幕,而不是两个元素。
// 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 - 也附加了事件监听器。
在其中,view 和 view1 都是子元素。
不确定为什么会这样。
干杯。
最佳答案
只有一个元素被滑动的原因是这一行:
e.source.animate(动画);
如果您将其替换为 viewContainer.animate(anim);
,滑动将如您所愿。
希望对您有所帮助。
关于javascript - 滑动手势不滑动容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25840122/