简体   繁体   English

UITableViewCell-拖动整行移动?

[英]UITableViewCell - drag whole row to move?

I'm trying to use a UITableViewController and allow the user to reorganize my data by dragging the rows. 我正在尝试使用UITableViewController并允许用户通过拖动行来重组我的数据。 This is working fine, except that the user has to tap on the relatively small UITableViewCellReorderControl on the right quarter of the cell to drag the row. 除用户必须点击单元格右四分之一上相对较小的UITableViewCellReorderControl来拖动行外,此方法工作正常。

Here's an example: 这是一个例子:

拖曳作品

As far as I can tell there's no way to get ahold of the UITableViewCellReorderControl or access its size or behavior through the UITableViewDelegate . 据我所知,没有办法保留UITableViewCellReorderControl或通过UITableViewDelegate访问其大小或行为。 Is there a way to customize drag behavior so that you can drag anywhere on the cell to move it up or down? 有没有一种方法可以自定义拖动行为,以便您可以在单元格上的任意位置拖动以将其向上或向下移动?

just expand the reorderControl to the size of cell. 只需将reorderControl扩展到单元格的大小即可。

extension UITableViewCell {
  var reoderControl: UIView? {
      for view in self.subviews {
          if view.description.contains("UITableViewCellReorderControl") {
              return view
          }
      }
      return nil
  }
}
class Cell: UITableViewCell {
     override func layoutSubviews() {
         super.layoutSubviews()
         reoderControl?.frame = bounds
     }
}

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

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