简体   繁体   English

在具有UITableView的UICollectionView中拖放

[英]Drag and Drop in UICollectionView that has UITableView

I'm having UICollectionView that scrolls horizontally. 我有UICollectionView水平滚动。 Each collection view cell has a table view that scrolls vertically. 每个集合视图单元格都有一个垂直滚动的表格视图。 I want to implement drag and drop of table view cell with in the table view itself as well as between different tableviews within each collection view cell. 我想在表视图本身以及每个集合视图单元格中的不同表视图之间实现表视图单元格的拖放。
Need some tutorial or help to achieve the functionality. 需要一些教程或帮助来实现功能。

@Satyam, it may help you to get some idea. @Satyam,它可以帮助你获得一些想法。 trello ios application has their own lib to get those behaviour. trello ios应用程序有自己的lib来获取这些行为。

-> uiViewController    
 -> uiScrollView
   -> uiPageViewController
     -> uiTableViewController
       -> drag and drop behaviour. while dragging, scrollview helps you to get the moving behaviour. 

https://www.cocoacontrols.com/controls/icarousel https://www.cocoacontrols.com/controls/icarousel

Quickly whipped up a test project, and as far as I've tested, it works fine. 快速完成一个测试项目,据我测试,它工作正常。

https://github.com/BridgeTheGap/Trelloesque https://github.com/BridgeTheGap/Trelloesque

The secret is the following two methods: 秘诀是以下两种方法:

func convertPointToIndexPath(point: CGPoint) -> (UITableView, NSIndexPath)? {
    if let tableView = [tableView1, tableView2, tableView3].filter({ $0.frame.contains(point) }).first {
        let localPoint = scrollView.convertPoint(point, toView: tableView)
        let lastRowIndex = focus?.0 === tableView ? tableView.numberOfRowsInSection(0) - 1 : tableView.numberOfRowsInSection(0)
        let indexPath = tableView.indexPathForRowAtPoint(localPoint) ?? NSIndexPath(forRow: lastRowIndex, inSection: 0)
        return (tableView, indexPath)
    }

    return nil
}

While not exactly the same, I think it has enough for you to work on. 虽然不完全相同,但我认为它足以让你继续工作。

  • Disclaimer: didn't have time to test it, so may be bug-prone. 免责声明:没有时间对其进行测试,因此可能容易出错。

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

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