SwiftUI ForEach 没有动画延迟
Posted
技术标签:
【中文标题】SwiftUI ForEach 没有动画延迟【英文标题】:SwiftUI ForEach no animation delay 【发布时间】:2019-12-14 01:21:27 【问题描述】:我最近更新到 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)
【问题讨论】:
我看到越来越多的区域在更新到 Xcode 11.3 后被报告为损坏... 【参考方案1】:这可能是由于双 VStack。您可以在 testView 中将VStack
更改为Group
。
Group
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)
【讨论】:
以上是关于SwiftUI ForEach 没有动画延迟的主要内容,如果未能解决你的问题,请参考以下文章