我正在制作一个国际象棋应用程序,这是主要的 vc 层次结构:MainViewController -> Board(UIView subclass) -> PieceView(UIImageView subclass) x 32 of my pieces。我在 viewDidLoad 中将板子添加到我的 viewController 中,它初始化了正方形和板子(正方形只是图纸)。问题是当我将拖放代表添加到我的董事会时,它可以处理移动 PieceView 的逻辑,它没有响应。
let dragInteraction = UIDragInteraction(delegate: self)
dragInteraction.isEnabled = true
PieceView.addInteraction(dragInteraction)
let dropInteraction = UIDropInteraction(delegate: self)
PieceView.addInteraction(dropInteraction)
我试图设置 Board isUserInteractionEnabled 和 PieceView 的所有变体,仍然不起作用。它甚至连委托调用都没有,因此它们中的代码与该问题无关。我的代码有什么问题?也许是 UIImageView 的子类?或者拖放的代表不是viewController?不管是什么,谢谢你的回答。
也许它有助于我按照本教程进行拖放的想法: 中等文章