gpt4 book ai didi

ios - 如何在 SwiftUI 中组合 3 个不同的同时手势?

转载 作者:行者123 更新时间:2023-12-03 20:55:16 27 4
gpt4 key购买 nike

试图在 SwiftUI 中同时编写 3 个手势,但 SwiftUI 的 SimultaneousGesture()仅适用于 2 个手势。

例如,我有一个基本的 View ,例如:

struct myRect: View {
var body: some View {
Rectangle()
.fill(Color.red)
.frame(width: 200, height: 200)
}
}

我需要这个 View 是可拖动、可旋转和可调整大小的。

我假设我需要使用 DragGesture() , RotationGesture() , 和 MagnificationGesture() .但我被卡住了 SimultaneousGesture()最多只接受 2 个手势。我怎样才能让这 3 个手势在我的 View 上工作?

编辑:

我应该指定这些手势必须同时工作。这与这里提出的问题完全一样: Pinch, Pan, and Rotate Text Simultaneously like Snapchat [SWIFT 3]

不过那是针对 UIKit 的。可以在 SwiftUI 中做到这一点吗?

最佳答案

您的看法 myRect可能与其他观点发生冲突。
我测试 SimultaneousGesture()修饰符,它可以通过任何顺序(例如打击)使用三个手势来正常工作:

struct myRect: View {
let rg = RotationGesture().onChanged({ a in
print("Angle = \(a.degrees)")
})
let dg = DragGesture(minimumDistance: 1, coordinateSpace: .local).onChanged({ v in
print("Translate = \(v.translation.width)")
})
let mg = MagnificationGesture().onChanged({ s in
print("scale = \(s)")
})
var body: some View {
Rectangle()
.fill(Color.red)
.frame(width: 200, height: 200)
.simultaneousGesture(rg)
.simultaneousGesture(mg)
.simultaneousGesture(dg)
}
}

关于ios - 如何在 SwiftUI 中组合 3 个不同的同时手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61132440/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com