UIDropInteractionDelegate performDrop不被调用吗? [英] UIDropInteractionDelegate performDrop not called?
问题描述
我正在尝试构建一个简单的测试应用程序以学习拖放API.对于这个问题,我只关注Drop场景.我有一个空白的View Controller,同时打开了safari应用程序(多任务),然后尝试将Google的图片拖到View Controller的视图上.
I am trying to build a simple test app to learn Drag and Drop APIs. For this question I am focusing only on the Drop scenario. I have a blank View Controller, with the safari app open (multitasking) I then try to drag an image from google onto the View Controller's view.
我可以将图像从野生动物园拖到应用程序的View Controller中,但是当我放开手时,以下调用将永远不会被调用:
I can drag the image from safari to my app's View Controller, but when I let go, this call below is never called:
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession)
这是我的代码:
class EditTestVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
view.addInteraction(UIDropInteraction(delegate: self))
}
}
extension EditTestVC:UIDropInteractionDelegate {
func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool { // 1
print("canHandle session: \(session)")
return true
// return session.canLoadObjects(ofClass: UIImage.self)
}
func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal { // 2
print("sessionDidUpdate session: \(session)")
return UIDropProposal(operation: .copy)
}
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
print("performDrop session: \(session)")
}
}
最上面的两个方法称为:
The top two methods are called, this one:
func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool
和这个:
func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal
所以,我试图弄清楚为什么这样一个:
So, I am trying to figure out why this one:
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession)
从不叫.
有什么建议吗?
推荐答案
我刚刚测试了您的代码,所有方法都被调用.一定是小故障.
I just tested your code and all methods are getting called. It must be a glitch.
故障排除步骤:
删除应用程序->重新启动模拟器->清理构建文件夹->重建->运行.您也可以先尝试在其他模拟器中运行以节省时间.
Delete app -> Restart the simulator -> Clean build folder -> Rebuild -> Run. You can also try running in different simulator first to save time.
这篇关于UIDropInteractionDelegate performDrop不被调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!