这是我的视图:
struct HomeView: View {
@ObservedObject var instance = Instance()
@State var dotColor = Color.gray
var repeatingAnimation: Animation {
Animation
.easeInOut(duration: 1.0)
.repeatForever()
}
var body: some View {
ZStack {
TabView(selection: $selectedTab) {
Settings(auth: auth)
.tabItem {
Image(systemName: "gear")
Text("Settings")
}.tag(0)
ZStack {
MapView(locationManager: locationManager)
Color.black.opacity(self.instance.status.opacity)
VStack {
Spacer()
Button(action: {
print("clicked")
withAnimation(self.repeatingAnimation) {
self.dotColor = Color.white
}
self.instance.changeStatus()
}){
HStack {
Text(self.instance.status.text)
.font(.system(size: 24))
.fontWeight(.bold)
.foregroundColor(Color.white)
Circle().frame(width: 12, height: 12)
.foregroundColor(self.dotColor)
.colorMultiply(self.dotColor)
.overlay(
Circle()
.stroke(Color.black, lineWidth: 1)
)
}
}.padding()
我的动画每秒钟将Circle()
的颜色从gray
变为white
。然而,它也会每秒钟改变我的ZStack
颜色不透明度(Color.black.opacity(self.instance.status.opacity)
) - 即使它与我的动画无关。
如果我移除动画,这种奇怪的行为就不会发生在ZStack的不透明度上。
我该如何解决这个问题?