一次拖放一个Object类

时间:2018-05-11 18:27:52

标签: ios swift drag-and-drop

我目前正在Drag and Drop中实施UITextView

UIDropInteractionDelegate canHande session:方法中,我同时接受图片和文字:

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

但有了这个,我发现了一个问题:如果我从网络上删除了一张图片,它会按预期接受image,但也会插入image URL string

有没有办法一次只接受一个class type

func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
    session.loadObjects(ofClass: UIImage.self) { (imageItems) in
        // image dropped
    }

    session.loadObjects(ofClass: NSString.self) { (stringItems) in
        // text dropped
    }
}

0 个答案:

没有答案