我最近更新到Xcode 11.3,现在我的ForEach
语句中以前正常工作的动画延迟失败了。下面是我的代码的简化版本。
谢谢
import SwiftUI
struct ContentView: View {
@State var show: Bool = false
var transition: AnyTransition {
let insertion = AnyTransition.move(edge: .trailing)
let removal = AnyTransition.move(edge: .leading)
return .asymmetric(insertion: insertion, removal: removal)
}
var body: some View {
VStack {
Button(action: { withAnimation { self.show.toggle() } } ) {
Text("start animation")
}
if show == true {
test()
.transition(transition)
}
}
}
}
struct wordArray: Identifiable{
var id = UUID()
var words: String
}
struct test: View{
let circleArray = [
wordArray(words: "This"),
wordArray(words: "Should"),
wordArray(words: "Be"),
wordArray(words: "Delayed"),
]
var body: some View{
VStack{
ForEach(circleArray) { wordArray in
Text("\(wordArray.words)")
.animation(Animation.easeInOut.delay(0.5))
}
Text("like")
.animation(Animation.easeInOut.delay(0.5))
Text("This")
.animation(Animation.easeInOut.delay(1))
}.frame(width: UIScreen.main.bounds.width)
}
}
答案 0 :(得分:0)
这可能是由于双VStack。您可以在testView中将let lovers = document.getElementsByClassName("lover")[0];
lovers.style.color = "red";
更改为VStack
。
Group