我已成立了我UITableView
使用新的拖放API。現在自定義視圖和Drop
if #available(iOS 11, *) {
self.tableView.dragDelegate = self
self.tableView.dropDelegate = self
self.tableView.dragInteractionEnabled = true
navigationController?.navigationBar.prefersLargeTitles = false
}
,我實現下面的方法可以使用自定義視圖爲d & d。
@available(iOS 11.0, *)
func dragInteraction(_ interaction: UIDragInteraction, previewForLifting item: UIDragItem, session: UIDragSession) -> UITargetedDragPreview? {
print("Custom Preview method called!")
let test = UITextView.init(frame: CGRect.init(x: 0, y: 0, width: 200, height: 200))
test.text = "sfgshshsfhshshfshsfh"
let dragView = interaction.view!
let dragPoint = session.location(in: dragView)
let target = UIDragPreviewTarget(container: dragView, center: dragPoint)
return UITargetedDragPreview(view: test, parameters:UIDragPreviewParameters(), target:target)
}
但是,這個方法永遠不會被調用。我從來沒有看到print()
或我的自定義視圖。任何想法,我做錯了什麼?
你應該設置'.dragInteractionEnabled = TRUE;並在你的'UIDragInteraction'對象設置的'.isEnabled = TRUE; –