【发布时间】:2021-07-15 18:58:17
【问题描述】:
我需要以编程方式为滚动视图的滚动设置动画。滚动视图包含 HStack 或 VStack。我测试的代码是这样的:
ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: spacing) {
ForEach(cids, id: \.self) { cid in
....
}
}
.onAppear {
withAnimation(Animation.easeInOut(duration: 4).delay(3)) {
proxy.scrollTo(testCid)
}
}
}
.frame(maxWidth: w, maxHeight: w / 2)
}
滚动视图确实落在带有testCid 的项目上,但是它没有动画。
一旦视图出现在屏幕上,滚动视图就已经在testCid...
如何为滚动设置动画?
【问题讨论】: