session.loadObjects(ofClass:UIImage.self)返回0个项目

时间:2019-07-14 19:04:13

标签: ios swift drag-and-drop

我正在为我的iPad应用程序添加拖放支持,并且UIDropInteractionDelegate的所有功能均已正确调用,但是我的会话项获得了0个项:

func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
    // Consume drag items (in this example, of type UIImage).
    session.loadObjects(ofClass: UIImage.self) { imageItems in
        let images = imageItems as! [UIImage] // images.count is 0
        /*
         If you do not employ the loadObjects(ofClass:completion:) convenience
         method of the UIDropSession class, which automatically employs
         the main thread, explicitly dispatch UI work to the main thread.
         For example, you can use `DispatchQueue.main.async` method.
         */
        self.logo.image = images.first
        self.saveImageFile(data: images.first?.pngData(), withName: COMPANY_LOGO)
    }
}

func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool {
    return session.hasItemsConforming(toTypeIdentifiers: [kUTTypeImage as String]) && session.items.count == 1
}

我要将图像从“照片”应用拖到放置目标。 有什么想法吗?

0 个答案:

没有答案