struct MyShimmer: View {
@State var show = false
var body: some View {
ZStack {
Color.black
VStack {
ZStack {
Text("Chao")
.foregroundColor(Color.white.opacity(0.5))
.font(.system(size: 40))
Text("Chao")
.foregroundColor(Color.white)
.font(.system(size: 40))
.mask(
Color.red.opacity(0.5)
.frame(width: 20)
.offset(x: self.show ? 180 : -130)
)
}
.onAppear(){
DispatchQueue.main.async {
withAnimation(Animation.default.speed(0.15).delay(0).repeatForever(autoreverses: false)){
self.show.toggle()
}
}
}
}
}
}
}
The problem is, if i comment out DispatchQueue.main.async, the whole view scales out from the top left corner or the screen.
if I put a button somewhere and do the withAnimation task without DispatchQueue.main.async when the button is clicked, it works fine
Anyone knows what happens?
i'm using XCode(Version 12.5.1 (12E507)) my mac is running macos big sur 11.4 (20F71)