Reputation: 15894
I'm having UICollectionView that scrolls horizontally. 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.
Upvotes: 3
Views: 2241
Reputation: 3601
Quickly whipped up a test project, and as far as I've tested, it works fine.
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.
Upvotes: 0
Reputation: 2689
You can try these tutorials
https://www.raywenderlich.com/63089/cookbook-moving-table-view-cells-with-a-long-press-gesture http://www.freshconsulting.com/create-drag-and-drop-uitableview-swift/ http://www.andypierz.com/blog/2014/11/9/basic-drag-and-drop-uitableviews-using-swift-and-core-data
http://www.iostute.com/2016/02/how-to-re-order-table-view-cell-by-drag.html
Some helpful Libraries
https://github.com/andreamazz/UIView-draggable
https://github.com/ra1028/RACollectionViewReorderableTripletLayout
https://github.com/lukescott/DraggableCollectionView
https://github.com/grillbiff/DragAndDropTableView
Upvotes: 1
Reputation: 621
@Satyam, it may help you to get some idea. trello ios application has their own lib to get those behaviour.
-> uiViewController
-> uiScrollView
-> uiPageViewController
-> uiTableViewController
-> drag and drop behaviour. while dragging, scrollview helps you to get the moving behaviour.
https://www.cocoacontrols.com/controls/icarousel
Upvotes: 0