SwiftUI AsyncImage 动画不当行为

Raf*_*sta 12 ios swift swiftui swiftui-asyncimage

在测试 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)
                )
            }
Run Code Online (Sandbox Code Playgroud)

每个图像只是 AccountRow 视图中的标准 AsyncImage:

    AsyncImage(url: URL(string: account.image)) {
            $0
                .resizable()
                .clipShape(Circle())
        } placeholder: {
            ProgressView()
        }
Run Code Online (Sandbox Code Playgroud)

Jac*_*ump 6

我遇到了类似的问题,如果您使用 init(url:scale:transaction:content:).

使用下面的代码,我让图像与纸张一起移动,消失时它没有移动,但由于纸张遮盖了它而被删除:

AsyncImage(
            url: URL(string: url),
            transaction: Transaction(animation: .default)
        ) { phase in
            switch phase {
            case .success(let image):
                image
                    .resizable()
            default:
                Image("defaultImage")
                    .resizable()
            }
        }
Run Code Online (Sandbox Code Playgroud)