简体   繁体   English

Titanium Mobile-向左/向右滑动TableView单元格以显示后面的另一行

[英]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.

相关问题 Swift 创建左、右滑动,长按 tableview 行单元格可移动 - Swift create left, right swipe with long press tableview row cell movable 向左和向右滑动表格行/单元格 - Swipe a Table Row/Cell Left and Right 如何在iOS SDK中的TableView中向左和向右滑动 - how to left and right swipe in tableview in iOS sdk 左右滑动手势可水平滚动tableview - Horizontal scrolling of tableview with swipe gesture left and right 在 swift 中显示更多按钮时取消在 tableview 单元格上向左滑动 - Cancel swipe left on tableview cell when showing more buttons in swift 如何在 swift 的 tableView 中向左滑动时更改单元格颜色 - How to change cell color on swipe left in tableView in swift 如何实现tableView的左右边缘的单元格边距? - How to realize the tableView's cell margin the left and right periphery of the tableView? 在移动设备上滑动(iPad设置屏幕)始终在右半部分滑动。 如何在左半部分执行滑动 - Swipe on mobile device (iPad Settings screen) always swipe on right half. How to perform Swipe in Left half 如何在类似于 iOS 邮件的 UITableView Cell 中实现从左到右滑动 - How to Implement Swipe Left to Right in UITableView Cell similar to iOS Mail 向左或向右滑动即可将集合视图单元格突出显示加载到视图控制器中 - Swipe left or right to load the view controller with the collection view cell highlight
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM