【发布时间】:2022-07-23 00:39:30
【问题描述】:
我正在尝试将我的手势提取到一个函数中,以便在我的一个 Swift 包中使用。我遇到的问题是,当我尝试在我的一个视图上使用它时,它不再符合 View。
以下代码产生此错误:Type 'any View' cannot conform to 'View'
struct ContentView: View {
var body: some View {
VStack {
Text("Placeholder")
}
.gesture(swipeDownGesture())
}
func swipeDownGesture() -> any Gesture {
DragGesture(minimumDistance: 0, coordinateSpace: .local).onEnded({ gesture in
if gesture.translation.height > 0 {
// Run some code
}
})
}
}
【问题讨论】: