SwiftUI处于Beta测试阶段,因此也许是一个错误,但是我在其他YouTube视频中看到了类似的功能,所以也许不是,测试非常简单。我正在创建一个可以水平拖动的圆圈。
import SwiftUI
struct ContentView : View {
@State private var location = CGPoint.zero
var body: some View {
return Circle()
.fill(Color.blue)
.frame(width: 300, height: 300)
.gesture(
DragGesture(minimumDistance: 10)
.onChanged { value in
print("value.location")
print(value.location)
self.location = CGPoint(
x: value.location.x,
y: 0)
}
)
.offset(x: self.location.x, y: self.location.y)
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
Run Code Online (Sandbox Code Playgroud)
结果是:
据我所知,回调中的value.location值DragGesture onChanged不应在这样的数字之间波动。查看日志,到处都是数字。我想念什么吗?