是否可以使用 iOS 11 拖放在 UITableView 中一次重新排序多个项目/单元格? [英] Is it possible to use iOS 11 Drag and Drop to reorder multiple items/cells at a time in UITableView?
问题描述
我知道在使用新的 UITableViewDropDelegate
和 UITableViewDragDelegate
委托时可以一次重新排序单个项目/单元格,但是否可以支持处理多个.
I know it's possible to reorder a single item/cell at a time when using the new UITableViewDropDelegate
and UITableViewDragDelegate
delegates but is it possible to support handling multiple.
例如,在这个屏幕截图中,我拿着一个物品:
For example in this screenshot I am holding a single item:
然后放下单元将其放置到位.
And dropping the cell puts it in to place.
但是,当我抓取多个单元格时,我得到了禁止进入的标志,并且单元格不会重新排序:
However when I grab multiple cells I get the no entry sign and the cells wont reorder:
如果我从另一个应用程序中获取多个项目,它可以正常工作,例如从 iMessage 中拖出多条消息:
If I multiple items from another app it works fine, for example dragging multiple messages out of iMessage:
在重新排序仅包含本地项目的表格视图时是否可以这样做,以便您可以更快地重新排序?
Is it possible to do this when reordering a table view with only local items so that you can reorder quicker?
这是我的代码:
UITableViewDragDelegate
extension DotViewController: UITableViewDragDelegate {
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
return [getDragItem(forIndexPath: indexPath)]
}
func tableView(_ tableView: UITableView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
return [getDragItem(forIndexPath: indexPath)]
}
func getDragItem(forIndexPath indexPath: IndexPath) -> UIDragItem {
// gets the item
}
}
UITableViewDropDelegate
extension DotViewController: UITableViewDropDelegate {
func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool {
return true
}
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
// Handles Drop
}
}
viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
tableView.dragDelegate = self
tableView.dropDelegate = self
tableView.dragInteractionEnabled = true
}
推荐答案
我用 UICollectionView
也试过了,结果发现:
推文链接 由 Tyler Fox 发布,他是拖拽的积极参与者.放弃开发,你也可以在与该主题相关的 2017-2018 WWDC 视频中看到他.
I've tried the same with UICollectionView
, then I found this:
link to tweet posted by Tyler Fox who was an active participant in the drag & drop development and you can also see him in the 2017-2018 WWDC videos related to the topic.
推文内容:
表格和集合视图不支持多项目重新排序的 UI,正确实现非常棘手.
不过,您可以使用 .unspecified
的意图并在会话期间为其提供自己的 UI,并且将接受放置.
如果您希望 API 支持它,请提交增强请求.感谢您提供有关您的特定用例的任何详细信息!
Table and collection view doesn’t support UI for multi-item reordering, it’s quite tricky to implement correctly.
You can use an intent of.unspecified
and provide your own UI for it during the session though, and the drop will be accepted.
Please file an enhancement request if you'd like to see it supported with API. Any details on your specific use case are appreciated!
这篇关于是否可以使用 iOS 11 拖放在 UITableView 中一次重新排序多个项目/单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!