[英]Titanium Mobile - Swipe TableView cell left/right to expose another row behind
I've been searching around on how to do this, but I've been unsuccessful. 我一直在寻找如何做到这一点,但我一直没有成功。
What I'm trying to accomplish is this: I have a TableView with, say, 5 rows. 我要完成的工作是:我有一个TableView,有5行。 I want to be able to swipe a row left to expose information "behind" the row.
我希望能够向左滑动一行以显示该行“后面”的信息。 Not sure if this would be done by adding an additional row to the TableView and placing it behind, or what?
不知道是否可以通过向TableView添加额外的一行并将其放在后面来完成此操作,或者是什么?
At the end of the day, what would be even cooler, would be to be able to swipe the row left OR right, and depending on which direction you swipe, the row behind gets populated with different information. 一天结束时,更酷的是,能够向左或向右滑动行,并且根据滑动的方向,后面的行会填充不同的信息。
Any ideas? 有任何想法吗?
From your description, it sounds like you want something similar to what Twitter does when you swipe across a Tweet. 根据您的描述,听起来您想要的是与在Twitter上滑动时Twitter所执行的操作类似的操作。
First, make sure the rows in the table don't have vertical/horizontal layouts. 首先,请确保表格中的行没有垂直/水平布局。
Then create the left and right swipe views you want for each row, like so: 然后为每一行创建所需的左右滑动视图,如下所示:
var leftSwipeView = Ti.UI.createView({
width: Ti.UI.FILL,
height: Ti.UI.FILL,
backgroundColor: '#ff0000', //just to make the effect apparent
visible: false
}
var rightSwipeView = Ti.UI.createView({
width: Ti.UI.FILL,
height: Ti.UI.FILL,
backgroundColor: '#00ff00', //just to make the effect apparent
visible: false,
}
row.add(leftSwipeView);
row.add(rightSwipeView);
row.addEventListener('swipe', function(e) {
if (e.direction == 'left'){
leftSwipeView.setVisible(true);
setTimeout(function(){leftSwipeView.setVisible(false);}, 2000);
}
if (e.direction == 'right'){
rightSwipeView.setVisible(true);
setTimeout(function(){rightSwipeView.setVisible(false);}, 2000);
}
});
The snippet I have up there will hide the views again after 2 seconds. 我在那里的代码段将在2秒后再次隐藏视图。 Hope that helps.
希望能有所帮助。
Found the perfect solution on Github. 在Github上找到了完美的解决方案。 https://github.com/rborn/TiSwipeToReveal
https://github.com/rborn/TiSwipeToReveal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.