gpt4 book ai didi

ios - SwiftUI .onTapGesture 从未调用过

转载 作者:行者123 更新时间:2023-12-01 15:48:55 25 4
gpt4 key购买 nike

附件是一个简单的 SwiftUI 结构,它显示了一组“扩展按钮”。我显示顶部按钮(其他 3 个是 1x1,在顶部按钮后面。)当用户点击顶部按钮时,它会扩展到 40x40 并以漂亮的动画移动下面的按钮。

我遇到的问题是没有任何底层按钮会响应它们的 .onTapGesture。我可以再次点击顶部按钮,动画反转,但是当点击其他按钮时没有任何反应。

import SwiftUI

struct MapTools: View {

@State private var isRotated = false

var body: some View {
ZStack {
Image("wheel")
.resizable()
.frame(width: 1, height: 1)
.foregroundColor(.mFoodColor)
.scaleEffect(self.isRotated ? 40 : 1)
.offset(x: self.isRotated ? -60 : 0, y: 0)
.onTapGesture {
withAnimation {
self.isRotated.toggle()
}
}

Image("locationPin")
.resizable()
.frame(width: 1, height: 1)
.foregroundColor(.mFoodColor)
.scaleEffect(self.isRotated ? 40 : 1)
.offset(x: self.isRotated ? -60 : 0, y: self.isRotated ? 60 : 0)
.onTapGesture {
withAnimation {
self.isRotated.toggle()
}
}

Image("locationArrow")
.resizable()
.frame(width: 1, height: 1)
.foregroundColor(.mFoodColor)
.scaleEffect(self.isRotated ? 40 : 1)
.offset(x: 0, y: self.isRotated ? 60 : 0)
.onTapGesture {
withAnimation {
self.isRotated.toggle()
}
}

Image("mapTools")
.resizable()
.frame(width: 40, height: 40)
.foregroundColor(.mFoodColor)
.rotationEffect(self.isRotated ? .degrees(90) : .degrees(0))
.onTapGesture {
withAnimation {
self.isRotated.toggle()
}
}
}
}
}

有人看到我做错了什么吗?

最佳答案

You have to use different bools for different Images to rotate them. Try with declaring 4 booleans for your four different images to rotate them

@State private var isFirstRotated = false
@State private var isSecondRotated = false
@State private var isThirdRotated = false
@State private var isFourthRotated = false

关于ios - SwiftUI .onTapGesture 从未调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61974714/

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