我有一组按顺时针旋转显示的按钮,但我无法正确单击它们:
我认为偏移有问题,但我不知道如何解决它,有什么建议吗?
这是代码:
struct CategoryView: View {
// Circle Radius
@State private var radius: Double = 150
let circleSize: Double = 350
// Degree of circle
@State private var degree = -90.0
let cards = ["John", "Mark", "Alex", "Kevin", "Jimmy"]
var body: some View {
ZStack {
let anglePerCount = Double.pi * 2.0 / Double(cards.count)
ForEach(0..<cards.count, id: \.self) { index in
let angle = Double(index) * anglePerCount
let xOffset = CGFloat(radius * cos(angle))
let yOffset = CGFloat(radius * sin(angle))
Button …Run Code Online (Sandbox Code Playgroud)