swiftui - 如何让 swiftui drop 委托被调用
问题描述
我希望你能帮忙。我正在尝试在 iOS 14 上的 SwiftUI 中实现纯文本的拖放。文本正在从浏览器中拖放到 TextEditor 上。文本被拖动正常,并且在放置时出现在 TextEditor 中,但没有调用委托函数。
如果您有任何想法或我可以在哪里寻找答案,我将不胜感激。
我的代码基本上是这样的:
import SwiftUI
struct ContentView: View {
@State private var entityText = ""
var body: some View {
VStack(alignment: .leading) {
TextEditor(text: $entityText)
.onDrop(of: [.text], delegate: MyDropDelegate())
.border(Color.black, width: 1)
.padding( 60.0)
}
}
}
struct MyDropDelegate: DropDelegate {
init() {
print("*** INIT ")
}
func performDrop(info: DropInfo) -> Bool {
print("*** Dropped \(info)")
guard info.hasItemsConforming(to: [.text]) else {
return false
}
return true
}
func validateDrop(info: DropInfo) -> Bool {
print("*** Validate")
return info.hasItemsConforming(to: [.text])
}
func dropEntered(info: DropInfo) {
print("*** ENTERED")
}
}
解决方案
推荐阅读
- ios - SwiftUI:VStack/HStack/ZStack 拖动手势不起作用
- javascript - 需要帮助将数组中的每个数字乘以它后面的数字,并让这些结果显示出来
- python - 单击按钮django时调用函数
- flutter - 如何在颤动中处理不同类型的字符(其他语言的字符和特殊字符)?
- angular - AmCharts Legend,如何在图表中的数据更改上重新单击未单击的图例
- python - 我可以像在交互模式下键入内容一样运行 Python 文件吗?
- javascript - API测试 | 验证响应
- python - python web抓取(如果使用所有标量值,则必须传递索引)
- javascript - 添加缓动/平滑滚动以使用js单击和拖动
- python - Python Gekko 流程图对象中有哪些方程式?