[英]SwiftUI animation affecting other views
Here is my View:这是我的观点:
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()
My animation, changes the color of the Circle()
from gray
to white
every second.我的 animation 每秒将
Circle()
的颜色从gray
变为white
。 However, it also changes my ZStack
color opacity ( Color.black.opacity(self.instance.status.opacity)
) every second - even though it's not related to my animation.但是,它也会每秒更改我的
ZStack
颜色不透明度( Color.black.opacity(self.instance.status.opacity)
) - 即使它与我的 animation 无关。
If I remove the animation this weird behaviour does not occur to the ZStack opacity.如果我删除 animation 这种奇怪的行为不会发生在 ZStack 不透明度上。
How can I fix this?我怎样才能解决这个问题?
You can disable animation of some modifier explicitly, like您可以明确禁用某些修饰符的 animation ,例如
Color.black.opacity(self.instance.status.opacity)
.animation(nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.