iOS 开发中的拖放功能全解析
1. 拖放数据加载方式
在 iOS 开发里,有两种获取拖放数据的方式。一种是直接在 dropInteraction(_:performDrop:) 方法里处理,另一种是获取 item provider 的引用并让其加载数据。示例代码如下:
// 第一种方式
// do something with color here
// 第二种方式
func dropInteraction(_ interaction: UIDropInteraction,
performDrop session: UIDropSession) {
for item in session.items {
let ip = item.itemProvider
ip.loadObject(ofClass: UIColor.self) { (color, error) in
if let color = color as? UIColor {
// do something with color here
}
}
}
}
这两种方式存在重要区别:
- loadObjects(ofClass:) :调用 session 的 loadObjects(ofC
超级会员免费看
订阅专栏 解锁全文
6

被折叠的 条评论
为什么被折叠?



