![](/img/trans.png)
[英]iOS 11 drag and drop support for UIViewcontroller with UITableView
[英]iOS 11 drag and drop custom files?
有沒有人在iOS 11中拖放自定義文件? 有大量的標准圖像和文本示例,但自定義文件呢? 即使像PDF這樣的標准文件也很有用。
創建一個PDFDocument
類並實現NSObject, NSItemProviderReading
協議,然后我們只需在那些大量的例子中將UIImage
更改為PDFDocument
類
更多細節 - > https://stackoverflow.com/a/45982118/3608824
另一種方法是因為我們有這個kUTTypePDF
統一類型標識符,只要你import MobileCoreServices
,根據dropInteraction(_:performDrop :)文檔,我們可以使用這個函數loadFileRepresentation(forTypeIdentifier:completionHandler:)
,這樣的東西應該工作:
func dropInteraction(_ interaction: UIDropInteraction, canHandle session: UIDropSession) -> Bool {
return session.hasItemsConforming(toTypeIdentifiers: [kUTTypePDF as String]) && session.items.count == 1
}
func dropInteraction(_ interaction: UIDropInteraction, sessionDidUpdate session: UIDropSession) -> UIDropProposal {
return UIDropProposal(operation: .copy)
}
func dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) {
if let itemProvider = (session.items.first)?.itemProvider {
itemProvider.loadDataRepresentation(forTypeIdentifier: kUTTypePDF as String) { (data, error) in
// do the work
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.