在测试 SwiftUI 时,我发现 AsyncImage 在动画过渡时效果不佳。在 UI 的其余部分移动到那里之前,它似乎已经确定了过渡的最终位置,使动画看起来很奇怪或关闭。
我的主要问题是:有什么方法可以访问 AsyncImage 的 SwiftUI 动画并使其与应用程序中的其他动画一起使用?
奇怪的是,如果我将其更改为其他视图(没有动画),则过渡行为正确,因此我认为问题的根源与 AsyncImage 的默认动画有关,以便在其phases
(加载、失败或加载)。
呈现的叠加层是这样描述的:
if isBottomSheetVisible {
VStack(alignment: .leading) {
AccountSelectorHeader()
ForEach(accounts) { account in
AccountRow(
account: account,
isLast: accounts.last == account
)
}
}
.padding(.bottom, 24)
.background(Color(.tableViewHeaderBackgroundColor)
.cornerRadius(24, corners: [.topLeft, .topRight])
.edgesIgnoringSafeArea(.bottom)
)
.transition(
.move(edge: .bottom)
)
}
每个图像只是 AccountRow 视图中的一个标准 AsyncImage:
AsyncImage(url: URL(string: account.image)) {
$0
.resizable()
.clipShape(Circle())
} placeholder: {
ProgressView()
}